How to get a list column names and datatypes of a table in PostgreSQL?
⚡TLDR
Get the column names and data types from a PostgreSQL table in a jiffy:
Replace 'your_table'
with your actual table name. The udt_name
field gives a less ambiguous data type representation than data_type
.
Retrieving more column details
To unravel extra details about your columns, such as the exact data type or their order:
psql Meta-Command for quick column details
For psql terminal lovers, use this one-liner:
This will reveal column details, including data types, in a neat table straight inside your terminal.
Delving into catalog tables for column details
For the curious geeks wishing to delve directly into PostgreSQL's system catalogs:
pg_attribute
stores the column names, while format_type
adds user-friendliness to data type string.
Grasp on data type nuances
Mastering data primitives:
text
signifies varying-length character strings.integer
andsmallint
handle numeric values void of decimal points.real
deals with inexact, variable-precision numbers, a.k.a floating-point.
Got a date
to remember? The timestamp
datatype marks time and date.
Linked
Linked
Was this article helpful?