kuda.ai | code. guitar. life.

Common Redshift Queries

created in October 2022

List Schemas in Database

select 
  s.nspname as table_schema,
  u.usename as owner
from pg_catalog.pg_namespace s
join pg_catalog.pg_user u on u.usesysid = s.nspowner
order by table_schema;

source: https://dataedo.com/kb/query/amazon-redshift/list-schemas-in-database

List Tables of Schema

SELECT table_name
FROM information_schema.tables
WHERE table_schema = '{{ SCHEMA }}'
      AND table_type = 'BASE TABLE'
ORDER BY table_name;

From https://dataedo.com/kb/query/amazon-redshift/list-of-tables-in-schema

List Columns of Table

SELECT column_name
FROM information_schema.columns
WHERE
    table_schema = '{{ SCHEMA }}'
    AND table_name = '{{ TABLE_NAME }}';