Weibo
Back to Blogs

Postgres Snippets

Jun 12 2024

Return data_type for each column name

postgres
SELECT
    column_name,
    data_type
FROM
    information_schema.columns
WHERE
    table_name = {table_name};
 
-- Result
/*
| column_name     | data_type                   |
| :-------------- | :-------------------------- |
| id              | integer                     |
| user_id         | bigint                      |
| thread_id       | character varying           |
| created_at      | timestamp without time zone |
*/
Built by Weibo Zhang