Skip to content
Advertisement

How to check for column attributes in postgreSQL?

I am new to SQL. Let say that when someone created a table like this in database named test1 of PostgreSQL:

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIME,
    updated_at TIMESTAMP DEFAULT CURRENT_TIME,
    contents VARCHAR(240) NOT NULL);

I make a query to the database and do not know how data in columns are stored. Is there a query to return the stored definition of the columns in the users table or a method to check this ?

For example: The result should return something like:

id column: SERIAL PRIMARY KEY
created_at: TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIME
...

Advertisement

Answer

You can use information_schema for this

select * 
from information_schema.columns 
where table_name = 'users'
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement