Reputation: 20261
How can a plain text list of the field names of table be retrieved from PostgreSQL database?
Upvotes: 0
Views: 112
Reputation: 116437
Just query INFORMATION_SCHEMA.COLUMNS, like this:
SELECT
column_name,
data_type,
character_maximum_length,
ordinal_position
FROM information_schema.columns
WHERE table_name = 'mytable'
Better still, INFORMATION_SCHEMA
is almost universally supported by all popular SQL databases, so this should work anywhere.
If you really want just dump plain text file recipe, you can execute this query using command line psql
and save it as CSV or something like that.
Upvotes: 1