prom icon indicating copy to clipboard operation
prom copied to clipboard

Better way to list columns in Postgres

Open Jaymon opened this issue 2 years ago • 2 comments

via

SELECT column_name FROM information_schema.columns where table_name = '<TABLE NAME>'

This seems way better than the horrible query I'm using right now

Search

  • postgres 12.8 get fields of table

Jaymon avatar Jan 18 '23 08:01 Jaymon

  • https://stackoverflow.com/questions/25639088/show-table-structure-and-list-of-tables-in-postgresql
  • https://www.postgresqltutorial.com/postgresql-administration/postgresql-describe-table/
  • postgres get table schema with query

Jaymon avatar Feb 17 '23 08:02 Jaymon

Looks like information_schema.columns doesn't give primary key information. I could combine the output of information_schema.columns with information_schema.table_constraints to make this work but I'm not sure it's worth it.

This is the postgres wiki solution on getting primary key

Jaymon avatar Mar 21 '23 22:03 Jaymon