0

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
...
1
  • 1
    Note that in modern Postgres versions, identity columns are recommended to be used over serial Commented Oct 7, 2021 at 11:58

1 Answer 1

1

You can use information_schema for this

select * 
from information_schema.columns 
where table_name = 'users'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, mate. Your answer is absolutely what I need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.