Categories:

Table, View, & Sequence DDL

SHOW COLUMNS

Lists the columns in the tables or views for which you have access privileges. This command can be used to list the columns for a specified table/view/schema/database (or the current schema/database for the session), or your entire account.

See also:

DESCRIBE TABLE

COLUMNS View (Information Schema)

Syntax

SHOW COLUMNS [ LIKE '<pattern>' ]
             [ IN { ACCOUNT | [ DATABASE ] <db_name> | [ SCHEMA ] <schema_name> | [ TABLE ] <table_name> | [ VIEW ] <view_name> } ]

Parameters

LIKE 'pattern'

Filters the command output by object name. The filter uses case-insensitive pattern matching, with support for SQL wildcard characters (% and _).

For example, the following patterns return the same results:

... LIKE '%testing%' ...
... LIKE '%TESTING%' ...
IN ACCOUNT | [ DATABASE ] db_name | [ SCHEMA ] schema_name | [ TABLE ] table_name | [ VIEW ] view_name

Specifies the scope of the command, which determines whether the command lists records only for the current/specified database or schema, or across your entire account:

Other than ACCOUNT, the keywords (DATABASE, SCHEMA, etc. ) are not required; you can set the scope by specifying only the name of the scope object; however, the name may need to be fully-qualified. Additionally, a scope object name is not required for DATABASE or SCHEMA if the session currently has a database in use.

Default: Depends on whether the session currently has a database in use:

DB in use

DATABASE is the default (i.e. the command returns the objects you have privileges to view in the database).

DB not in use

ACCOUNT is the default (i.e. the command returns the objects you have privileges to view in your account).

Usage Notes

  • The command does not require a running warehouse to execute.

  • The command returns a maximum of 10K records for the specified object type, as dictated by the access privileges for the role used to execute the command; any records above the 10K limit are not returned, even with a filter applied.

    To view results for which more than 10K records exist, query the corresponding view (if one exists) in the Information Schema.

  • To post-process the output of this command, you can use the RESULT_SCAN function, which treats the output as a table that can be queried.

Output

The command output provide column properties and metadata in the following columns:

+------------+-------------+-------------+-----------+-------+---------+------+------------+---------+---------------+---------------+
| table_name | schema_name | column_name | data_type | null? | default | kind | expression | comment | database_name | autoincrement |
|------------+-------------+-------------+-----------+-------+---------+------+------------+---------+---------------+---------------|

Column

Description

table_name

Name of the table the columns belong to.

schema_name

Schema for the table.

column_name

Name of the column.

data_type

Column data type and applicable properties, such as length, precision, scale, nullable, etc.; note that character and numeric columns display their generic data type rather than their defined data type (i.e. TEXT for all character types, FIXED for all fixed-point numeric types, and REAL for all floating-point numeric types).

null?

Whether the column can contain NULL values.

default

Default value, if any, defined for the column.

kind

Not applicable for columns (always displays COLUMN as the value).

expression

comment

Comment, if any, for the column.

database_name

Database for the table.

autoincrement

Auto-increment start and increment values, if any, for the column.

Examples

create or replace table dt_test (n1 number default 5, n2_int integer default n1+5, n3_bigint bigint autoincrement, n4_dec decimal identity (1,10),
                                 f1 float, f2_double double, f3_real real,
                                 s1 string, s2_var varchar, s3_char char, s4_text text,
                                 b1 binary, b2_var varbinary,
                                 bool1 boolean,
                                 d1 date,
                                 t1 time,
                                 ts1 timestamp, ts2_ltz timestamp_ltz, ts3_ntz timestamp_ntz, ts4_tz timestamp_tz);

show columns in table dt_test;

+------------+-------------+-------------+---------------------------------------------------------------------------------------+-------+----------------+--------+------------+---------+---------------+-------------------------------+
| table_name | schema_name | column_name | data_type                                                                             | null? | default        | kind   | expression | comment | database_name | autoincrement                 |
|------------+-------------+-------------+---------------------------------------------------------------------------------------+-------+----------------+--------+------------+---------+---------------+-------------------------------|
| DT_TEST    | PUBLIC      | N1          | {"type":"FIXED","precision":38,"scale":0,"nullable":true}                             | true  | 5              | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | N2_INT      | {"type":"FIXED","precision":38,"scale":0,"nullable":true}                             | true  | DT_TEST.N1 + 5 | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | N3_BIGINT   | {"type":"FIXED","precision":38,"scale":0,"nullable":true}                             | true  |                | COLUMN |            |         | TEST1         | IDENTITY START 1 INCREMENT 1  |
| DT_TEST    | PUBLIC      | N4_DEC      | {"type":"FIXED","precision":38,"scale":0,"nullable":true}                             | true  |                | COLUMN |            |         | TEST1         | IDENTITY START 1 INCREMENT 10 |
| DT_TEST    | PUBLIC      | F1          | {"type":"REAL","nullable":true}                                                       | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | F2_DOUBLE   | {"type":"REAL","nullable":true}                                                       | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | F3_REAL     | {"type":"REAL","nullable":true}                                                       | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | S1          | {"type":"TEXT","length":16777216,"byteLength":16777216,"nullable":true,"fixed":false} | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | S2_VAR      | {"type":"TEXT","length":16777216,"byteLength":16777216,"nullable":true,"fixed":false} | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | S3_CHAR     | {"type":"TEXT","length":1,"byteLength":4,"nullable":true,"fixed":false}               | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | S4_TEXT     | {"type":"TEXT","length":16777216,"byteLength":16777216,"nullable":true,"fixed":false} | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | B1          | {"type":"BINARY","length":8388608,"byteLength":8388608,"nullable":true,"fixed":true}  | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | B2_VAR      | {"type":"BINARY","length":8388608,"byteLength":8388608,"nullable":true,"fixed":false} | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | BOOL1       | {"type":"BOOLEAN","nullable":true}                                                    | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | D1          | {"type":"DATE","nullable":true}                                                       | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | T1          | {"type":"TIME","precision":0,"scale":9,"nullable":true}                               | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | TS1         | {"type":"TIMESTAMP_LTZ","precision":0,"scale":9,"nullable":true}                      | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | TS2_LTZ     | {"type":"TIMESTAMP_LTZ","precision":0,"scale":9,"nullable":true}                      | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | TS3_NTZ     | {"type":"TIMESTAMP_NTZ","precision":0,"scale":9,"nullable":true}                      | true  |                | COLUMN |            |         | TEST1         |                               |
| DT_TEST    | PUBLIC      | TS4_TZ      | {"type":"TIMESTAMP_TZ","precision":0,"scale":9,"nullable":true}                       | true  |                | COLUMN |            |         | TEST1         |                               |
+------------+-------------+-------------+---------------------------------------------------------------------------------------+-------+----------------+--------+------------+---------+---------------+-------------------------------+