Question

Just moved from SSMS to Redshift (using DBeaver) and am wondering if there's a good option for getting table descriptions. In SQL server you could write a great query against information_schema to pull column names, datatypes, etc. Any similar options in Redshift?

Était-ce utile?

La solution

The INFORMATION_SCHEMA tables are available in Redshift.

It may be that your chosen query tool (DBeaver) is hiding the schema in the GUI. However you should still be able to query them as normal.

This is certainly the case for me when I'm using Navicat. If you want to see the schema then it is visible when using SQL Workbench or SQuirreL.

2016-04-04: AWS have created a much simpler view that provides complete CREATE TABLE statements including all the Redshift specific stuff. Get them from here: https://github.com/awslabs/amazon-redshift-utils/tree/master/src/AdminViews

Autres conseils

Looks like you are looking for something like this : http://rocky-says.blogspot.com/2015/01/amazon-redshift-generate-table-ddl.html

Here is the query that will help you : Just replace the < TABLE > and < SCHEMA> with your table name and Schema

SELECT DISTINCT n.nspname AS schemaname
 ,c.relname AS tablename
 ,a.attname AS COLUMN
 ,a.attnum AS column_position
 ,pg_catalog.format_type(a.atttypid, a.atttypmod) AS TYPE
 ,pg_catalog.format_encoding(a.attencodingtype) AS encoding
  ,a.attisdistkey AS distkey
 ,a.attsortkeyord AS sortkey
 ,a.attnotnull AS notnull
 ,a.attencodingtype AS compression
 ,con.conkey AS primary_key_column_ids
 ,con.contype AS con_type
FROM pg_catalog.pg_namespace n
 ,pg_catalog.pg_class c
 ,pg_catalog.pg_attribute a
 ,pg_constraint con
 ,pg_catalog.pg_stats stats
WHERE n.oid = c.relnamespace
 AND c.oid = a.attrelid
 AND a.attnum > 0
 AND c.relname NOT LIKE '%pkey'
 AND lower(c.relname) = ''
 AND n.nspname = ''
 AND c.oid = con.conrelid(+)
ORDER BY A.ATTNUM
;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top