问题
I am looking for a programmatic way to get the Snowflake table schema, is there a way for that?
回答1:
You can use a SHOW command to list table columns e.g.
SHOW COLUMNS IN TABLE MYSCHEMA.MYTABLE;
Note that SHOW commands have the advantage that they do not require a running warehouse to execute, so are zero cost queries.
回答2:
Use this query:
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_schema ilike 'schema' -- put your schema name here
and table_name ilike 'table' -- put your table name here
order by ordinal_position;
Please note, this would incur a cost as it will require a running warehouse. If you are looking for a no-cost solution check Nathan Griffiths' answer. If you are looking for a query-based predictable solution you can use this answer.
来源:https://stackoverflow.com/questions/61917196/list-all-columns-wtih-datatype-in-specific-table-in-snowflake