List all columns wtih datatype in specific table in Snowflake

旧街凉风 提交于 2021-01-28 14:09:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!