Home postgresql Get a list of database tables and its fields

Get a list of database tables and its fields

Author

Date

Category

There are several databases. How to get a list of database tables and fields of these tables in Postgres?


Answer 1, Authority 100%

select table_name, column_name
from information_schema.columns.
Where Table_schema = 'Public'

Answer 2, Authority 50%

select datname from pg_database where datistemplate = false;
Select table_name from information_schema.Tables Where Table_schema = 'Public' Order by Table_Name;
Select Table_Name, column_name from information_schema.columns Where Table_schema = 'Public'

Update

- PK Key
SELECT
 PG_ATTRIBUTE.ATTNAME,
 Format_Type (pg_attribute.atttypid, pg_attribute.atttypmod)
From pg_index, pg_class, pg_attribute, pg_namespace
Whater
 PG_CLASS.OID = 'Tablename' :: RegClass and
 indrelid = pg_class.oid and
 NSPName = 'Public' and
 pg_class.relnamespace = pg_namespace.oid and
 pg_attribute.attrelid = pg_class.oid and
 pg_attribute.attnum = any (PG_INDEX.INDKEY)
 And indisprimary

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions