Postgres Snippets

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 |
*/

Copyright 2024 Weibo Zhang ©️