How to get list of table columns in PostgreSQL

We can get list columns using describe in Oracle/SQL Server or other RDBMS. But, describe not works in PostgreSQL. We can get the list of columns in PostgreSQL using \d table_name or running query on table INFORMATION_SCHEMA.COLUMNS.

Method 1: Get list of columns of table in PostgreSQL using \d table_name

company=# \d emp;

Table "public.emp" Column | Type | Modifiers ----------+-----------------------+----------- empno | numeric(4,0) | not null ename | character varying(10) | job | character varying(9) | mgr | numeric(4,0) | hiredate | date | sal | numeric(7,2) | comm | numeric(7,2) | deptno | numeric(2,0) |

Method2: Running query on table INFORMATION_SCHEMA.COLUMNS

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

column_name | data_type | character_maximum_length -------------+-------------------+-------------------------- empno | numeric | ename | character varying | 10 job | character varying | 9 mgr | numeric | hiredate | date | sal | numeric | comm | numeric | deptno | numeric | (8 rows)

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: