List All Columns in a Table in Redshift
This query lists all columns in a specific table on AWS Redshift.
SELECT
ordinal_position AS position,
column_name,
data_type,
CASE WHEN character_maximum_length IS NOT NULL
THEN character_maximum_length
ELSE numeric_precision END AS max_length,
is_nullable,
column_default AS default_value
FROM
information_schema.columns
WHERE table_name = 'sample_table_name' -- enter table name here
--AND table_schema = 'sample_schema_name'
ORDER BY ordinal_position;
The query is quite self explainatory. Each row of the query output represents a column of the table queried. And each column will represent the a feature of a column of the table queried.
To cite this content, please use:
@article{
leehanchung,
author = {Lee, Hanchung},
title = {List All Columns in a Table in Redshift},
year = {2021},
howpublished = {\url{https://leehanchung.github.io/}},
url = {https://leehanchung.github.io/2021-08-10-useful-redshift-sql/}
}