List Table Column Names and Data Types

In YSQL you can query the system table INFORMATION_SCHEMA.COLUMNS to list details about each of the columns in table.

Example:

				
					 yugabyte=# CREATE SCHEMA test_schema;
 CREATE SCHEMA

 yugabyte=# CREATE TABLE test_schema.test_table (c1 INT PRIMARY KEY, c2 VARCHAR, c3 VARCHAR(30) NOT NULL);
 CREATE TABLE
 
 yugabyte=# SELECT column_name, data_type, character_maximum_length, numeric_precision, numeric_scale
 yugabyte-#   FROM information_schema.columns
 yugabyte-#  WHERE table_schema = 'test_schema'
 yugabyte-#    AND table_name = 'test_table'
 yugabyte-#  ORDER BY ordinal_position;
  column_name |     data_type     | character_maximum_length | numeric_precision | numeric_scale
 -------------+-------------------+--------------------------+-------------------+---------------
  c1          | integer           |                          |                32 |             0
  c2          | character varying |                          |                   |
  c3          | character varying |                       30 |                   |
 (3 rows)
				
			

Have Fun!