Home > Blockchain >  How to check for column attributes in postgreSQL?
How to check for column attributes in postgreSQL?

Time:10-07

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
...

CodePudding user response:

You can use information_schema for this

select * 
from information_schema.columns 
where table_name = 'users'
  • Related