patternsqlCritical
List all columns for a specified table
Viewed 0 times
columnsallforlisttablespecified
Problem
I'm looking for a precise piece of information in a database which I have no knowledge about. The database is on a separate machine, but I can log into it, and launch a
It's a third-party product, and they are slow to answer questions. I know the data is inside that database, so I want to do a little bit of reverse-engineering.
Given a table name, is it possible to get a list of the names of the columns in that table?
For example, in SQL Server, it's possible to dump a table into a reusable
psql command line, with administrator rights.It's a third-party product, and they are slow to answer questions. I know the data is inside that database, so I want to do a little bit of reverse-engineering.
Given a table name, is it possible to get a list of the names of the columns in that table?
For example, in SQL Server, it's possible to dump a table into a reusable
CREATE statement, which textually lists all the columns the table is composed of.Solution
In addition to the command line
Note: As per the example above, make sure the values are enclosed within quotes.
\d+ you already found, you could also use the Information Schema to look up the column data, using information_schema.columns:SELECT *
FROM information_schema.columns
WHERE table_schema = 'your_schema'
AND table_name = 'your_table'
;Note: As per the example above, make sure the values are enclosed within quotes.
Code Snippets
SELECT *
FROM information_schema.columns
WHERE table_schema = 'your_schema'
AND table_name = 'your_table'
;Context
StackExchange Database Administrators Q#22362, answer score: 657
Revisions (0)
No revisions yet.