vfclists
vfclists

Reputation: 20261

How can a list of table's field names be queried from PostgreSQL?

How can a plain text list of the field names of table be retrieved from PostgreSQL database?

Upvotes: 0

Views: 112

Answers (1)

mvp
mvp

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

Related Questions