0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.