In addition to the command line \d+ <table_name> 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.

Answer from bhamby on Stack Exchange
🌐
CommandPrompt Inc.
commandprompt.com › education › postgresql-list-all-columns-of-a-specific-table
PostgreSQL - List All Columns of a Specific Table — CommandPrompt Inc.
February 1, 2023 - In PostgreSQL, the “\d” command, “\d+” command, “information_schema”, and “pgAdmin” are used to list all columns of a table.
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham
Discussions

Show table structure and list of tables in PostgreSQL - Stack Overflow
All I dug up was some ultra-lame hack to get column names for an already known table name by doing a "WHERE 1 != 1" or some such so that no actual rows could be returned. Not very informative, that. Surely I've missed the point, somewhere. So enlighten me, please. What, pray tell, are the PostgreSQL-ish SQL queries one uses so as to explore a given DB's table structure? What is the PostgreSQL translation for "SHOW ... More on stackoverflow.com
🌐 stackoverflow.com
python - PostgreSQL - query all tables' all table columns - Stack Overflow
How can I query all tables' all table columns in a database? Method I've tried: get all table names using select tablename from pg_tables where schemaname = 'public' Process cmd string using UNION More on stackoverflow.com
🌐 stackoverflow.com
Way to search all tables in a database for a specific column name?
Depends on the DBMS. Most (all?) have some views that you can query that contain all information about database objects. In Oracle this would look something like SELECT table_name, column_name FROM all_tab_cols where column_name = 'THIS' They're called dictionary views or information schema etc. More on reddit.com
🌐 r/SQL
27
16
February 15, 2023
How to get a list column names and data-type of a table in PostgreSQL?
\d+ tablename in psql More on reddit.com
🌐 r/PostgreSQL
4
1
November 21, 2019
People also ask

Does Coefficient work with both Google Sheets and Excel?
Yes, Coefficient supports both Google Sheets and Microsoft Excel. You can install Coefficient from the Google Workspace Marketplace for Sheets or from Microsoft AppSource for Excel.
🌐
coefficient.io
coefficient.io › home
PostgreSQL Get Column Names: A Step-by-Step Guide
Can I export data back to my business systems with Coefficient?
Yes, Coefficient supports two-way data sync. You can not only import live data from your business systems but also export updated data back to them. Supported export actions include UPDATE (modify existing records), INSERT (create new records), UPSERT (update or insert), and DELETE operations. This works with systems like Salesforce, HubSpot, QuickBooks, Snowflake, and databases.
🌐
coefficient.io
coefficient.io › home
PostgreSQL Get Column Names: A Step-by-Step Guide
How much does Coefficient cost?
Coefficient offers 4 pricing tiers: Free Plan (3 connectors, forever free), Starter Plan ($59/user/month for individual users), Pro Plan ($99/user/month for 5 users), and custom Enterprise pricing. All paid plans include a 30-day free trial. Our Free trial let's you leverage our Pro plan at no cost so you can test the product with every feature available.
🌐
coefficient.io
coefficient.io › home
PostgreSQL Get Column Names: A Step-by-Step Guide
🌐
Dataedo
dataedo.com › kb › query › postgresql › list-table-columns-in-database
List table columns in PostgreSQL database - PostgreSQL Data Dictionary Queries
November 7, 2018 - select table_schema, table_name, ordinal_position as position, column_name, data_type, case when character_maximum_length is not null then character_maximum_length else numeric_precision end as max_length, is_nullable, column_default as default_value from information_schema.columns where table_schema not in ('information_schema', 'pg_catalog') order by table_schema, table_name, ordinal_position;
🌐
PostgreSQL
postgresql.org › docs › current › infoschema-columns.html
PostgreSQL: Documentation: 18: 35.17. columns
May 14, 2026 - 35.17. columns # The view columns contains information about all table columns (or view columns) in the database. System columns (ctid, …
🌐
Coefficient
coefficient.io › home
PostgreSQL Get Column Names: A Step-by-Step Guide
December 18, 2025 - To list the columns for a table, simply type d table_name in the psql prompt. This will display the table’s structure, including the column names and their data types. ... This will show the column names and data types for the users table.
Find elsewhere
🌐
TablePlus
tableplus.com › blog › 2018 › 04 › postgresql-how-to-list-all-available-columns.html
PostgreSQL - How to list all columns? | TablePlus
April 9, 2018 - SELECT * FROM information_schema.columns WHERE table_schema = 'schema_name' AND table_name = 'table_name';
🌐
MLJAR
mljar.com › notebooks › postgresql-python-show-columns
Show columns from table in PostgreSQL
# if connection was used and closed it is reopen here if conn.closed: conn = create_new_connection() # run query with conn: with conn.cursor() as cur: # query db try: cur.execute(""" SELECT attname AS col, atttypid::regtype AS datatype FROM pg_attribute WHERE attrelid = %s::regclass AND attnum > 0 AND NOT attisdropped ORDER BY attnum;""", ("products",)) # check for errors except psycopg.ProgrammingError as e: raise psycopg.ProgrammingError(f""" Problem running query: {e} Did you spell everything correctly? You can use show tables and columns recipes. """) # print the results print("Columns of products:") for column in cur.fetchall(): print(f"{column}") Choosing advanced option reveals database schema field. Public is the default schema for PostgreSQL databases.
🌐
Neon
neon.com › postgresql › postgresql-administration › postgresql-describe-table
PostgreSQL DESCRIBE TABLE
To get information on columns of a table, you query the information_schema.columns catalog.
🌐
Devart
devart.com › dbforge › postgresql › studio › postgresql-describe-table.html
PostgreSQL DESCRIBE TABLE
However, the information schema does not include details about PostgreSQL-specific features. For that information, you need to look at the system catalogs or other PostgreSQL-specific views. Let's see how it works! In order to retrieve details about the columns in a specific table, you can query the information_schema.columnsi view.
🌐
Softbuilder
soft-builder.com › home › how to list all table columns in postgresql database
How to list all table columns in PostgreSQL database - Softbuilder Blog
February 13, 2022 - To list down all tables columns on a specific table in the a PostgreSQL database using psql command-line, you can use \dS your_table_name.
🌐
Quadratic
quadratichq.com › blog › postgres-list-tables
How to List Database Tables in PostgreSQL
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'; The query returns the full list of user-generated tables in the database. You can query Postgres to list columns ...
Top answer
1 of 2
150

SHOW TABLES and DESCRIBE TABLE are MySQL-specific admin commands, and nothing to do with standard SQL.

You want the:

\d

and

\d+ tablename

commands from psql.

These are implemented client-side. I find this odd myself, and would love to move them server-side as built-in SQL commands one day.

Other clients provide other ways to browse the structure - for example, PgAdmin-III.

If you want a portable way to get table structure in code, you should use the information_schema views, which are SQL-standard. See information_schema. They're available in MySQL, PostgreSQL, Ms-SQL, and most other DBs. The downside is that they're fiddlier to use, so they aren't convenient for quick access when you're just browsing a DB structure.

2 of 2
59

As per the Documentation

SELECT
    table_schema || '.' || table_name as show_tables
FROM
    information_schema.tables
WHERE
    table_type = 'BASE TABLE'
AND
    table_schema NOT IN ('pg_catalog', 'information_schema');

for more convenience make it as a function

create or replace function show_tables() returns SETOF text as $$
SELECT
    table_schema || '.' || table_name as show_tables
FROM
    information_schema.tables
WHERE
    table_type = 'BASE TABLE'
AND
    table_schema NOT IN ('pg_catalog', 'information_schema');
$$
language sql; 

So we can get the tables using

select show_tables()

For the table description

 select column_name, data_type, character_maximum_length
 from INFORMATION_SCHEMA.COLUMNS where table_name ='table_name';

as a Function

create or replace function describe_table(tbl_name text) returns table(column_name   
varchar, data_type varchar,character_maximum_length int) as $$
select column_name, data_type, character_maximum_length
from INFORMATION_SCHEMA.COLUMNS where table_name = $1;
$$
language 'sql';

select  *  from describe_table('a_table_name');
🌐
Dataedo
dataedo.com › kb › query › postgresql › list-columns-names-in-specific-table
List all columns in specific table in PostgreSQL database - PostgreSQL Data Dictionary Queries
November 13, 2018 - Article for: PostgreSQL ▾ SQL Server Azure SQL Database Oracle database Snowflake Amazon Redshift IBM Db2 Teradata Vertica MySQL MariaDB · Query below returns a list of all columns in a specific table in PostgreSQL.
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › how-to-check-column-types-in-postgresql
How to Check Column Types in PostgreSQL? - GeeksforGeeks
July 23, 2025 - It queries the information_schema.columns view, providing detailed information about each column's type. To retrieve the column types in PostgreSQL, we have several options at our disposal, including the \d command, the pg_typeof() function, ...
🌐
Beekeeper Studio
beekeeperstudio.io › blog › postgresql-information-schema
PostgreSQL Information_Schema Guide for Database Management | Beekeeper Studio
April 9, 2024 - This command will return a list of all the table names in your ‘current database’ in the ‘public’ schema. ... Use the information_schema.columns view to extract detailed information about the columns of a particular table:
Top answer
1 of 6
23

You can do this in a single query by using array_agg() and a join on the information_schema.tables and information_schema.columns tables.

This would return something similar to your expected output:

select
    t.table_name,
    array_agg(c.column_name::text) as columns
from
    information_schema.tables t
inner join information_schema.columns c on
    t.table_name = c.table_name
where
    t.table_schema = 'public'
    and t.table_type= 'BASE TABLE'
    and c.table_schema = 'public'
group by t.table_name;

Here I'm taking all the tables first, then I join it with the columns tables, and finally use array_agg() to aggregate them all to an array, grouped by the table name.

Hope it helps :) Feel free to ask if you have any doubts.

2 of 6
4

Since you're working in Python, clearest if you handle this in two steps I think. First, use this query to retrieve table/column name pairs:

select table_name, column_name 
from information_schema.columns 
where table_name in (
    select tablename from pg_tables where schemaname = 'public');

Then, stick the results into a defaultdict:

from collections import defaultdict

my_cols = <your code to execute the query above and fetch all rows>
column_mapping = defaultdict(list)
for tablename, colname in my_cols:
    column_mapping[tablename].append(colname)

This will give you:

>>> column_mapping
defaultdict(<type 'list'>, {'table_1': ['time', 'col'], 'table_2': ['time', 'col'], 'table_3': ['time', 'col]})

Which you can convert trivially with:

>>> column_mapping.items()
[('table_1', ['time', 'col']), ('table_2', ['time', 'col']), ('table_3', ['time', 'col])]
🌐
PostgreSQL
postgresql.org › docs › current › logical-replication-col-lists.html
PostgreSQL: Documentation: 18: 29.5. Column Lists
May 14, 2026 - /* pub # */ \dRp+ Publication p1 ... t | t | t | t | none | f Tables: "public.t1" (id, a, b, d) psql can be used to show the column lists (if defined) for each table....
🌐
Simular
simular.ai › workflow › how-to-list-postgres-columns-a-practical-guide-for-teams
How to List Postgres Columns: A Practical Guide for Teams
May 7, 2026 - As a business owner or marketer, you may live more in GUIs than in SQL. You can still get column names reliably without touching the terminal. ... Most BI tools (Metabase, Looker Studio connectors, Power BI, etc.) have a schema or field explorer. ... Connect the tool to your Postgres database. Navigate to the dataset or table.