Discover Data Types for Columns in a Result Set

After executing a query in YSQL it’s not obvious what are the underlying data types of the columns returned in the result set.

Luckliy we have the dba-friendly \gdesc command for that purpose. It will display the data types for each column in the most recently executed SQL statement!

Example:

				
					
yugabyte=# SELECT current_date, now(), random(), ARRAY[1,2,3], ARRAY['A','B','C'];
 current_date |              now              |       random       |  array  |  array
--------------+-------------------------------+--------------------+---------+---------
 2022-04-18   | 2022-04-18 18:33:48.202925+00 | 0.0395637578330934 | {1,2,3} | {A,B,C}
(1 row)

yugabyte=# \gdesc
    Column    |           Type
--------------+--------------------------
 current_date | date
 now          | timestamp with time zone
 random       | double precision
 array        | integer[]
 array        | text[]
(5 rows)
				
			

Have fun!