SELECT
    column_name,
    data_type
FROM
    information_schema.columns
WHERE
    table_name = 'table_name';

with the above query you can retrieve columns and its datatype.

Answer from selva on Stack Overflow
🌐
Coefficient
coefficient.io › home
PostgreSQL Get Column Names: A Step-by-Step Guide
December 18, 2025 - To fetch the column names, we use the cur.execute() method to execute a SELECT * FROM query on the target table, but with a LIMIT 0 clause to prevent the actual retrieval of any data.
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 does Coefficient's automated refresh work?
Coefficient allows you to schedule automatic data refreshes at intervals you choose: hourly (1, 2, 4, or 8 hours), daily, weekly, or monthly. Once scheduled, your spreadsheet data automatically updates from your connected systems without any manual work. You can also trigger manual refreshes anytime with an on-sheet button or through the sidebar.
🌐
coefficient.io
coefficient.io › home
PostgreSQL Get Column Names: A Step-by-Step Guide
Top answer
1 of 4
3

I don't know why you would ever need to do this, but it is possible using some of the JSON functions introduced in 9.3.

SELECT json_object_keys(row_to_json(t)) FROM
 (SELECT * FROM table1
  LEFT JOIN table2 ON table1.id = table2.tbl1_id LIMIT 1) t;

This will give you the name of every column returned for a single row. Without the LIMIT you would get the columns repeated for every row returned. If you wanted to see the values returned as well you can get more complex:

WITH t as
  (SELECT * FROM table1
   LEFT JOIN table2 ON table1.id = table2.tbl1_id LIMIT 1)
SELECT json_data.key, json_data.value
FROM t, json_each_text(row_to_json(t)) AS json_data;

Both these queries will return all the columns even if they are named the same. If all you want is a list of unique column names, you can utilize hstore:

CREATE EXTENSION hstore; --Create the extension if you need it.

SELECT akeys(hstore(t)) as array_of_columns
FROM
(SELECT * FROM table1
 LEFT JOIN table2 ON table1.id = table2.tbl1id LIMIT 1) t;
2 of 4
1

The only reasonable approach I can come up with is to do something like this. Schema location plays into this, but I'm just posting the basic idea. SQL doesn't have reflection at run time unless you go and hit meta data tables, which is what you seem to be trying to achieve here.

SELECT table1.* 
INTO x
      FROM table1 
           LEFT JOIN table2 
                     ON table1.id = table2.tbl1_id LIMIT 0;

select *
from information_schema.columns
where table_Name = 'x';

Also interesting enough while traveling the Internets over lunch I ran into this. Works with PostgreSQL 8.2.0 or higher.

https://github.com/theory/colnames/tree/master/test/sql

🌐
Delft Stack
delftstack.com › home › howto › postgres › get column names in postgresql
How to Get Column Names in PostgreSQL | Delft Stack
March 11, 2025 - Whether you’re a developer, a ... there are two primary methods to get column names: using the \d+ command in the psql command-line interface and executing a SQL query....
🌐
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'; ... In TablePlus, you can be able to see all columns from the Postgres GUI with a spreadsheet-like view. From the data table, you can see columns with data: Or from the database structure, ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › get-column-names-from-postgresql-table-using-psycopg2
Get column names from PostgreSQL table using Psycopg2 - GeeksforGeeks
July 23, 2025 - First, we connect the PostgreSQL database using psycopg2.connect() method, then we create a cursor using cursor() method, after that we use the cursor() then extract the first element from it using slicing.
Find elsewhere
🌐
Dataedo
dataedo.com › kb › query › postgresql › find-tables-with-specific-column-name
Find tables with specific column name in PostgreSQL database - PostgreSQL Data Dictionary Queries
November 5, 2018 - select t.table_schema, t.table_name from information_schema.tables t inner join information_schema.columns c on c.table_name = t.table_name and c.table_schema = t.table_schema where c.column_name = 'last_name' and t.table_schema not in ...
🌐
Collecting Wisdom
collectingwisdom.com › home › postgresql: how to list column names and types for table
PostgreSQL: How to List Column Names and Types for Table - Collecting Wisdom
September 11, 2024 - SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'products'; column_name | data_type -------------+----------- productid | integer date_sold | date name | text · The resulting table shows the column name and datatype for each column in the table.
🌐
PostgreSQL
postgresql.org › docs › 8.4 › queries-select-lists.html
PostgreSQL: Documentation: 8.4: Select Lists
July 24, 2014 - The simplest kind of select list ... (as defined in Section 4.2). For instance, it could be a list of column names: SELECT a, b, c FROM ......
🌐
PostgreSQL
postgresql.org › message-id › AANLkTilsjTAXyN5DghR3M2U4c8w48UVxhov4-8igMpd1@mail.gmail.com
PostgreSQL: Re: [SQL] How to Get Column Names from the Table
July 7, 2010 - Hi, To get column names only select column_name from information_schema.columns where table_name='captor_prime_aggregates'; Thanks Sreelatha On Wed, Jul 7, 2010 at …
🌐
PostgreSQL Extension Network
pgxn.org › dist › colnames
colnames: Lists the column names in a PostgreSQL RECORD value / PostgreSQL Extension Network
This extension contains a single SQL function, colnames(), that takes a record value as its argument and returns an array of the names of the columns in that record:
🌐
Postgres Professional
postgrespro.com › list › thread-id › 1463718
Thread: Query to get column-names in table via PG tables? : Postgres Professional
Ken Johanson wrote: >>> I am looking for expertise on how to program the equivalent to this >>> query, but using the pg_catalog tables, which I understand have fewer >>> security restrictions than information_schema in some cases: >>> >>> SELECT column_name >>> FROM information_schema.columns >>> WHERE table_catalog=? AND table_schema=? AND table_name=? >>> ORDER BY ordinal_position >> >> Do what psql does...launch it with psql -E, and it will echo any >> internal queries it makes back to you.
🌐
Stack Overflow
stackoverflow.com › questions › 57375761 › getting-list-of-column-names-in-a-table-postgresql
Getting list of column names in a table (PostgreSQL) - Stack Overflow
I have searched online for some solutions, but none give expected results. Here is what I have tried. select column_name from information_schema.columns where table_name = 'Accounts';
🌐
Baeldung
baeldung.com › home › sql queries › how to retrieve column names from a table in sql
How to Retrieve Column Names From a Table in SQL Baeldung on SQL
August 4, 2024 - In this section, we check out various methods for retrieving column names from a table in PostgreSQL. To begin with, the INFORMATION_SCHEMA view provides metadata about the columns of all tables. By querying this view, we can retrieve the column names for a specific table.
🌐
Naysan
naysan.ca › 2022 › 01 › 19 › list-column-names-from-postgresql-table
List Column Names from PostgreSQL Table | Naysan Saran
# If you want to list only the column names select column_name from information_schema.columns where table_name='your_table_name'; # If you also want to add the data type select column_name, data_type from information_schema.columns where table_name='your_table_name';
🌐
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 - Alternatively, you can use the “information_schema” with the help of the “SELECT” statement to get the column names of a specific table: SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'public' AND ...
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham
🌐
GitHub
github.com › brianc › node-postgres › issues › 908
How do I get column names of a table? · Issue #908 · brianc/node-postgres
December 29, 2015 - Hi, I want to get the column names of a table. This is what I'm doing now: var selectQuery = 'SELECT * FROM "' + tableName + '" LIMIT 1'; pgClient.query(selectQuery, function(err, result){ var columns = _.pluck(result.fields, 'name'); })
Author   brianc