Snowflake SQL Tutorial 112 - SHOW Is Not Queryable, Until You Wrap It - RESULT_SCAN

Snowflake SQL · Episode 112

In this post we are going to cover SHOW, DESCRIBE and COMMENT in Snowflake.

SHOW lists objects. DESCRIBE lists what is inside one. COMMENT is how you write down what a thing is for. They are three commands everybody learns in the first week and then stops thinking about, because their output looks like a report you can only read with your eyes.

It is not a report. One function turns it into a table you can filter, count, sum and join, and once it is a table SHOW and the catalog start disagreeing with each other in the open.

We will start with the plainest SHOW there is and build it up step by step.

Every query below was run on a real Snowflake account, and every result you see is the output it gave back.

Episode 112 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.

Let's create something to look at

We want an object with some description on it, so there is something for DESCRIBE to find. The table below has a comment on itself and a comment on three of its four columns. ISSUED deliberately has none, because we are going to come back and give it one later.

There is also a view over the table, and a second table with nothing in it, so that we have more than one kind of object to count.

Sample data
-- Sample data for this post.
-- A table with a comment on itself and on three of its four columns, three
-- rows in it, a view over it, and a second table with nothing in it.
USE DATABASE DEMO_DB;
USE SCHEMA PUBLIC;

CREATE OR REPLACE TABLE INVOICES_T112 (
    INVOICE_ID  INT           COMMENT 'the invoice number, not gapless',
    CUSTOMER    VARCHAR(40)   COMMENT 'who it is for',
    AMOUNT      NUMBER(10,2)  COMMENT 'gross, in account currency',
    ISSUED      DATE
) COMMENT = 'episode 112 probe table';

INSERT INTO INVOICES_T112 (INVOICE_ID, CUSTOMER, AMOUNT, ISSUED)
SELECT 1001, 'Ana Ltd',  120.00, '2026-01-15'::DATE UNION ALL
SELECT 1002, 'Ben GmbH', 340.50, '2026-02-02'::DATE UNION ALL
SELECT 1003, 'Cleo SA',   75.25, '2026-02-19'::DATE;

CREATE OR REPLACE VIEW BIG_INVOICES_T112
    COMMENT = 'invoices over 100'
AS SELECT INVOICE_ID, CUSTOMER, AMOUNT
   FROM INVOICES_T112
   WHERE AMOUNT > 100;

CREATE OR REPLACE TABLE PAYMENTS_T112 (
    PAYMENT_ID  INT,
    INVOICE_ID  INT,
    PAID        NUMBER(10,2)
);

Let's start with SHOW TABLES

The plainest version lists every table in the schema.

Query
SHOW TABLES IN SCHEMA PUBLIC;
Result13 rows · 27 columns · scroll →
Scroll the grid sideways. This is everything SHOW TABLES returns.
created_onnamedatabase_nameschema_namekindcommentcluster_byrowsbytesownerretention_timeautomatic_clusteringchange_trackingsearch_optimizationsearch_optimization_progresssearch_optimization_bytesis_externalenable_schema_evolutionowner_role_typeis_eventis_hybridis_icebergis_dynamicis_immutableis_interactiverow_timestamperror_logging
2026-09-28 18:27:08.999000-07:00CUSTOMERSDEMO_DBPUBLICTABLE101536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:07.395000-07:00DEPARTMENTSDEMO_DBPUBLICTABLE41024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:15.165000-07:00DOCS_XMLDEMO_DBPUBLICTABLE41536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:08.115000-07:00EMPLOYEESDEMO_DBPUBLICTABLE82048ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:11.646000-07:00EVENTS_JSONDEMO_DBPUBLICTABLE43072ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:17.808000-07:00INVOICES_T112DEMO_DBPUBLICTABLEepisode 112 probe table31024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 03:50:28.146000-07:00JSON_LOADEDDEMO_DBPUBLICTABLE112560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:14.430000-07:00JSON_TEXT_RAWDEMO_DBPUBLICTABLE111536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:09.808000-07:00ORDERSDEMO_DBPUBLICTABLE411536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112DEMO_DBPUBLICTABLE00ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:10.959000-07:00SALES_RAWDEMO_DBPUBLICTABLE81536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:16.148000-07:00TYPED_SHAPESDEMO_DBPUBLICTABLE22560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 20:10:07.808000-07:00XML_LOADEDDEMO_DBPUBLICTABLE44096ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF

Our two tables are in there along with everything else the schema holds from earlier posts. It is a wide grid: created_on, name, kind, comment, rows and bytes are the ones people read, and the rest are flags.

If that is too much, there is a shorter form.

Query
SHOW TERSE TABLES IN SCHEMA PUBLIC;
Result13 rows · 5 columns
created_onnamekinddatabase_nameschema_name
2026-09-28 18:27:08.999000-07:00CUSTOMERSTABLEDEMO_DBPUBLIC
2026-09-28 18:27:07.395000-07:00DEPARTMENTSTABLEDEMO_DBPUBLIC
2026-09-28 18:27:15.165000-07:00DOCS_XMLTABLEDEMO_DBPUBLIC
2026-09-28 18:27:08.115000-07:00EMPLOYEESTABLEDEMO_DBPUBLIC
2026-09-28 18:27:11.646000-07:00EVENTS_JSONTABLEDEMO_DBPUBLIC
2026-09-28 18:27:17.808000-07:00INVOICES_T112TABLEDEMO_DBPUBLIC
2026-09-27 03:50:28.146000-07:00JSON_LOADEDTABLEDEMO_DBPUBLIC
2026-09-28 18:27:14.430000-07:00JSON_TEXT_RAWTABLEDEMO_DBPUBLIC
2026-09-28 18:27:09.808000-07:00ORDERSTABLEDEMO_DBPUBLIC
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112TABLEDEMO_DBPUBLIC
2026-09-28 18:27:10.959000-07:00SALES_RAWTABLEDEMO_DBPUBLIC
2026-09-28 18:27:16.148000-07:00TYPED_SHAPESTABLEDEMO_DBPUBLIC
2026-09-27 20:10:07.808000-07:00XML_LOADEDTABLEDEMO_DBPUBLIC

TERSE gives the same list of tables with a handful of columns instead of the full set. Nothing is filtered out. Only the width changed.

Can we put a WHERE clause on it?

We only want the two tables from this post, and the obvious way to ask for that is a WHERE clause. Let's try.

Refused
SHOW TABLES IN SCHEMA PUBLIC WHERE "name" LIKE '%T112';
Query failed — Snowflake returned an error
001003 (42000): SQL compilation error:
syntax error line 1 at position 29 unexpected 'WHERE'.

syntax error, unexpected 'WHERE'. A SHOW does not take one.

So let's treat it as a table and select from it instead.

Refused
SELECT "name" FROM SHOW TABLES IN SCHEMA PUBLIC;
Query failed — Snowflake returned an error
001003 (42000): SQL compilation error:
syntax error line 1 at position 31 unexpected 'IN'.

Also a syntax error. You cannot select from a SHOW either.

SHOW has exactly one filter of its own, and it is LIKE.

Query
SHOW TABLES LIKE '%T112' IN SCHEMA PUBLIC;
Result2 rows · 27 columns · scroll →
created_onnamedatabase_nameschema_namekindcommentcluster_byrowsbytesownerretention_timeautomatic_clusteringchange_trackingsearch_optimizationsearch_optimization_progresssearch_optimization_bytesis_externalenable_schema_evolutionowner_role_typeis_eventis_hybridis_icebergis_dynamicis_immutableis_interactiverow_timestamperror_logging
2026-09-28 18:27:17.808000-07:00INVOICES_T112DEMO_DBPUBLICTABLEepisode 112 probe table31024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112DEMO_DBPUBLICTABLE00ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF

That is what we wanted, and it is as far as most people ever get. It works, but a pattern on the name is all it can do. You cannot filter on the row count, you cannot sort it, and you cannot count what comes back.

Now let's wrap it and make it a table

Here is the thing that changes the whole picture. The output of any query is kept for a while and can be fetched again by its id. LAST_QUERY_ID() gives us the id of the statement we just ran, and RESULT_SCAN hands back its result as a table.

So first we run the SHOW, so that it is the last thing that ran.

Run this first
SHOW TABLES IN SCHEMA PUBLIC;
Result13 rows · 27 columns · scroll →
We only need this to have run. The next query reads its output.
created_onnamedatabase_nameschema_namekindcommentcluster_byrowsbytesownerretention_timeautomatic_clusteringchange_trackingsearch_optimizationsearch_optimization_progresssearch_optimization_bytesis_externalenable_schema_evolutionowner_role_typeis_eventis_hybridis_icebergis_dynamicis_immutableis_interactiverow_timestamperror_logging
2026-09-28 18:27:08.999000-07:00CUSTOMERSDEMO_DBPUBLICTABLE101536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:07.395000-07:00DEPARTMENTSDEMO_DBPUBLICTABLE41024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:15.165000-07:00DOCS_XMLDEMO_DBPUBLICTABLE41536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:08.115000-07:00EMPLOYEESDEMO_DBPUBLICTABLE82048ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:11.646000-07:00EVENTS_JSONDEMO_DBPUBLICTABLE43072ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:17.808000-07:00INVOICES_T112DEMO_DBPUBLICTABLEepisode 112 probe table31024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 03:50:28.146000-07:00JSON_LOADEDDEMO_DBPUBLICTABLE112560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:14.430000-07:00JSON_TEXT_RAWDEMO_DBPUBLICTABLE111536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:09.808000-07:00ORDERSDEMO_DBPUBLICTABLE411536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112DEMO_DBPUBLICTABLE00ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:10.959000-07:00SALES_RAWDEMO_DBPUBLICTABLE81536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:16.148000-07:00TYPED_SHAPESDEMO_DBPUBLICTABLE22560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 20:10:07.808000-07:00XML_LOADEDDEMO_DBPUBLICTABLE44096ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF

And now we select from it, with a WHERE clause and an ORDER BY, like any other table.

Query
SELECT "name", "rows", "bytes", "comment"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T112'
ORDER BY "name";
Result2 rows · 4 columns
namerowsbytescomment
INVOICES_T11231024episode 112 probe table
PAYMENTS_T11200

Four columns, two rows, filtered the way we asked. INVOICES_T112 reports its rows, its bytes and its comment. PAYMENTS_T112 has no comment, and SHOW reports that as an empty string rather than as a NULL. Hold on to that, because the catalog does not agree.

Why the column names are in quotes

Have a look at the double quotes around "name", "rows", "bytes" and "comment". A SHOW returns its column names in lower case, and a lower case identifier has to be quoted or Snowflake will look for the upper case one and not find it. That is the only awkward part of this, and it is the whole trick.

And if it is a table, it aggregates. Let's run the SHOW again and count instead of listing.

Run this first
SHOW TABLES IN SCHEMA PUBLIC;
Result13 rows · 27 columns · scroll →
created_onnamedatabase_nameschema_namekindcommentcluster_byrowsbytesownerretention_timeautomatic_clusteringchange_trackingsearch_optimizationsearch_optimization_progresssearch_optimization_bytesis_externalenable_schema_evolutionowner_role_typeis_eventis_hybridis_icebergis_dynamicis_immutableis_interactiverow_timestamperror_logging
2026-09-28 18:27:08.999000-07:00CUSTOMERSDEMO_DBPUBLICTABLE101536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:07.395000-07:00DEPARTMENTSDEMO_DBPUBLICTABLE41024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:15.165000-07:00DOCS_XMLDEMO_DBPUBLICTABLE41536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:08.115000-07:00EMPLOYEESDEMO_DBPUBLICTABLE82048ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:11.646000-07:00EVENTS_JSONDEMO_DBPUBLICTABLE43072ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:17.808000-07:00INVOICES_T112DEMO_DBPUBLICTABLEepisode 112 probe table31024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 03:50:28.146000-07:00JSON_LOADEDDEMO_DBPUBLICTABLE112560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:14.430000-07:00JSON_TEXT_RAWDEMO_DBPUBLICTABLE111536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:09.808000-07:00ORDERSDEMO_DBPUBLICTABLE411536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112DEMO_DBPUBLICTABLE00ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:10.959000-07:00SALES_RAWDEMO_DBPUBLICTABLE81536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:16.148000-07:00TYPED_SHAPESDEMO_DBPUBLICTABLE22560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 20:10:07.808000-07:00XML_LOADEDDEMO_DBPUBLICTABLE44096ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
Query
SELECT COUNT(*)        AS TABLES_MATCHING,
       SUM("rows")     AS ROWS_BETWEEN_THEM
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T112';
Result1 row · 2 columns
TABLES_MATCHINGROWS_BETWEEN_THEM
23

A COUNT and a SUM over the output of a SHOW. That is the episode, and everything else is a consequence of it.

Now that both are queryable, they disagree

There are two ways to ask what is in a schema. We have just made one of them countable, so let's ask both the same question with the same filter.

Run this first
SHOW TABLES IN SCHEMA PUBLIC;
Result13 rows · 27 columns · scroll →
created_onnamedatabase_nameschema_namekindcommentcluster_byrowsbytesownerretention_timeautomatic_clusteringchange_trackingsearch_optimizationsearch_optimization_progresssearch_optimization_bytesis_externalenable_schema_evolutionowner_role_typeis_eventis_hybridis_icebergis_dynamicis_immutableis_interactiverow_timestamperror_logging
2026-09-28 18:27:08.999000-07:00CUSTOMERSDEMO_DBPUBLICTABLE101536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:07.395000-07:00DEPARTMENTSDEMO_DBPUBLICTABLE41024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:15.165000-07:00DOCS_XMLDEMO_DBPUBLICTABLE41536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:08.115000-07:00EMPLOYEESDEMO_DBPUBLICTABLE82048ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:11.646000-07:00EVENTS_JSONDEMO_DBPUBLICTABLE43072ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:17.808000-07:00INVOICES_T112DEMO_DBPUBLICTABLEepisode 112 probe table31024ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 03:50:28.146000-07:00JSON_LOADEDDEMO_DBPUBLICTABLE112560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:14.430000-07:00JSON_TEXT_RAWDEMO_DBPUBLICTABLE111536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:09.808000-07:00ORDERSDEMO_DBPUBLICTABLE411536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112DEMO_DBPUBLICTABLE00ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:10.959000-07:00SALES_RAWDEMO_DBPUBLICTABLE81536ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-28 18:27:16.148000-07:00TYPED_SHAPESDEMO_DBPUBLICTABLE22560ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
2026-09-27 20:10:07.808000-07:00XML_LOADEDDEMO_DBPUBLICTABLE44096ACCOUNTADMIN1OFFOFFOFFNULLNULLNNROLENNNNNNOFFOFF
Query
SELECT COUNT(*) AS OBJECTS_FROM_SHOW_TABLES
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T112';
Result1 row · 1 column
OBJECTS_FROM_SHOW_TABLES
2

Now the catalog view.

Query
SELECT TABLE_NAME, TABLE_TYPE, ROW_COUNT, COMMENT
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC' AND RIGHT(TABLE_NAME, 5) = '_T112'
ORDER BY TABLE_NAME;
Result3 rows · 4 columns
TABLE_NAMETABLE_TYPEROW_COUNTCOMMENT
BIG_INVOICES_T112VIEWNULLinvoices over 100
INVOICES_T112BASE TABLE3episode 112 probe table
PAYMENTS_T112BASE TABLE0NULL

A different answer. There is a third object matching that pattern, and the second column says why: BIG_INVOICES_T112 is a VIEW. INFORMATION_SCHEMA.TABLES includes views. SHOW TABLES does not.

Query
SELECT TABLE_TYPE, COUNT(*) AS HOW_MANY
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC' AND RIGHT(TABLE_NAME, 5) = '_T112'
GROUP BY TABLE_TYPE
ORDER BY TABLE_TYPE;
Result2 rows · 2 columns
TABLE_TYPEHOW_MANY
BASE TABLE2
VIEW1

Counted by kind, it is two base tables and one view.

Look at the last column of the catalog grid as well. PAYMENTS_T112 has no comment and the catalog reports a real NULL, where the SHOW grid above reported an empty string. Same table, same missing comment, two different answers. If you ever write something that tests a comment for IS NULL, it matters which of these two you read it from.

And the view's ROW_COUNT is NULL too, because a view holds nothing to count.

The thing to take away from this section

These two look interchangeable and they are not. One includes views and one does not, and nothing warns you. If you are counting objects, say which of them you counted.

Let's DESCRIBE the table

DESCRIBE answers the other question: not what objects are there, but what is inside one of them.

Query
DESCRIBE TABLE INVOICES_T112;
Result4 rows · 13 columns · scroll →
nametypekindnull?defaultprimary keyunique keycheckexpressioncommentpolicy nameprivacy domainwrite default
INVOICE_IDNUMBER(38,0)COLUMNYNULLNNNULLNULLthe invoice number, not gaplessNULLNULLNULL
CUSTOMERVARCHAR(40)COLUMNYNULLNNNULLNULLwho it is forNULLNULLNULL
AMOUNTNUMBER(10,2)COLUMNYNULLNNNULLNULLgross, in account currencyNULLNULLNULL
ISSUEDDATECOLUMNYNULLNNNULLNULLNULLNULLNULLNULL

Four rows, one per column, and a very wide grid to say it in. name, type, kind, null? and default are the useful ones. Then primary key, unique key, check, expression, comment, policy name, privacy domain and write default.

Most of those are NULL here, which is normal. And the comment column shows the three comments we wrote, with a NULL against ISSUED.

The same RESULT_SCAN trick works on it, because it is just another query's output.

Query
SELECT "name", "type", "null?", "default", "comment"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
ORDER BY "name";
Result4 rows · 5 columns
nametypenull?defaultcomment
AMOUNTNUMBER(10,2)YNULLgross, in account currency
CUSTOMERVARCHAR(40)YNULLwho it is for
INVOICE_IDNUMBER(38,0)YNULLthe invoice number, not gapless
ISSUEDDATEYNULLNULL

Five columns instead of thirteen, and sorted by name, which DESCRIBE on its own will not do for you.

DESC is the same command spelled shorter.

Query
DESC TABLE INVOICES_T112;
Result4 rows · 13 columns · scroll →
nametypekindnull?defaultprimary keyunique keycheckexpressioncommentpolicy nameprivacy domainwrite default
INVOICE_IDNUMBER(38,0)COLUMNYNULLNNNULLNULLthe invoice number, not gaplessNULLNULLNULL
CUSTOMERVARCHAR(40)COLUMNYNULLNNNULLNULLwho it is forNULLNULLNULL
AMOUNTNUMBER(10,2)COLUMNYNULLNNNULLNULLgross, in account currencyNULLNULLNULL
ISSUEDDATECOLUMNYNULLNNNULLNULLNULLNULLNULLNULL

Identical output. Use whichever one you can type faster.

Does DESCRIBE VIEW work on a table?

First, the ordinary use. DESCRIBE VIEW on the view.

Query
DESCRIBE VIEW BIG_INVOICES_T112;
Result3 rows · 13 columns · scroll →
nametypekindnull?defaultprimary keyunique keycheckexpressioncommentpolicy nameprivacy domainwrite default
INVOICE_IDNUMBER(38,0)COLUMNYNULLNNNULLNULLNULLNULLNULLNULL
CUSTOMERVARCHAR(40)COLUMNYNULLNNNULLNULLNULLNULLNULLNULL
AMOUNTNUMBER(10,2)COLUMNYNULLNNNULLNULLNULLNULLNULLNULL

Three rows, because the view selects three columns. No comments on them, because a view does not inherit the comments of the table underneath it.

Now something I did not know. Let's point DESCRIBE VIEW at the table.

Query
DESCRIBE VIEW INVOICES_T112;
Result4 rows · 13 columns · scroll →
nametypekindnull?defaultprimary keyunique keycheckexpressioncommentpolicy nameprivacy domainwrite default
INVOICE_IDNUMBER(38,0)COLUMNYNULLNNNULLNULLthe invoice number, not gaplessNULLNULLNULL
CUSTOMERVARCHAR(40)COLUMNYNULLNNNULLNULLwho it is forNULLNULLNULL
AMOUNTNUMBER(10,2)COLUMNYNULLNNNULLNULLgross, in account currencyNULLNULLNULL
ISSUEDDATECOLUMNYNULLNNNULLNULLNULLNULLNULLNULL

It works. Four rows, comments and all, exactly as DESCRIBE TABLE gave us. The two keywords are interchangeable here.

What is not interchangeable is the name of something that does not exist.

Refused
DESCRIBE TABLE NO_SUCH_TABLE_T112;
Query failed — Snowflake returned an error
002003 (42S02): SQL compilation error:
Table 'NO_SUCH_TABLE_T112' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on TABLE NO_SUCH_TABLE_T112.

does not exist or not authorized, which is the same message you get for a table you have no privilege on. Snowflake will not tell you which of the two it is.

Now the one worth the episode: DESCRIBE RESULT

DESCRIBE works on a stored object. It also works on a result, which means you can ask what types a query produced without building a table out of it.

Let's run a query with an expression in it. AMOUNT is declared as NUMBER(10,2), and we are going to multiply it.

Query
SELECT INVOICE_ID,
       CUSTOMER,
       AMOUNT * 1.2          AS WITH_TAX,
       DATE_TRUNC('MONTH', ISSUED) AS MONTH_ISSUED
FROM INVOICES_T112
ORDER BY INVOICE_ID;
Result3 rows · 4 columns
INVOICE_IDCUSTOMERWITH_TAXMONTH_ISSUED
1001Ana Ltd144.0002026-01-01
1002Ben GmbH408.6002026-02-01
1003Cleo SA90.3002026-02-01

Sensible numbers. Now let's ask what the types of those four columns are.

Query
DESCRIBE RESULT LAST_QUERY_ID();
Result4 rows · 13 columns · scroll →
nametypekindnull?defaultprimary keyunique keycheckexpressioncommentpolicy nameprivacy domainwrite default
INVOICE_IDNUMBER(38,0)COLUMNYNULLNNNULLNULLNULLNULLNULLNULL
CUSTOMERVARCHAR(40)COLUMNYNULLNNNULLNULLNULLNULLNULLNULL
WITH_TAXNUMBER(12,3)COLUMNYNULLNNNULLNULLNULLNULLNULLNULL
MONTH_ISSUEDDATECOLUMNYNULLNNNULLNULLNULLNULLNULLNULL

INVOICE_ID and CUSTOMER came straight from the table and kept their types. MONTH_ISSUED is a DATE.

And WITH_TAX is NUMBER(12,3). We started from NUMBER(10,2) and multiplied by 1.2, and Snowflake decided the result needed two more digits of precision and one more of scale.

That decision is written nowhere in the query. DESCRIBE RESULT is how you see it, and it is the thing to reach for before you create a table from a SELECT and wonder why the column came out wider than the one it came from.

And because it is a result like any other, it scans too.

Query
SELECT "name", "type"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result4 rows · 2 columns
nametype
INVOICE_IDNUMBER(38,0)
CUSTOMERVARCHAR(40)
WITH_TAXNUMBER(12,3)
MONTH_ISSUEDDATE

So where do comments actually live?

In more than one place, and they do not all answer the same way. Let's run the DESCRIBE again and pull just the comments out of it.

Run this first
DESCRIBE TABLE INVOICES_T112;
Result4 rows · 13 columns · scroll →
nametypekindnull?defaultprimary keyunique keycheckexpressioncommentpolicy nameprivacy domainwrite default
INVOICE_IDNUMBER(38,0)COLUMNYNULLNNNULLNULLthe invoice number, not gaplessNULLNULLNULL
CUSTOMERVARCHAR(40)COLUMNYNULLNNNULLNULLwho it is forNULLNULLNULL
AMOUNTNUMBER(10,2)COLUMNYNULLNNNULLNULLgross, in account currencyNULLNULLNULL
ISSUEDDATECOLUMNYNULLNNNULLNULLNULLNULLNULLNULL
Query
SELECT "name", "comment"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
ORDER BY "name";
Result4 rows · 2 columns
namecomment
AMOUNTgross, in account currency
CUSTOMERwho it is for
INVOICE_IDthe invoice number, not gapless
ISSUEDNULL

Three columns have a comment. ISSUED has a NULL, because we never gave it one.

The catalog agrees.

Query
SELECT COLUMN_NAME, COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'PUBLIC' AND TABLE_NAME = 'INVOICES_T112'
ORDER BY ORDINAL_POSITION;
Result4 rows · 2 columns
COLUMN_NAMECOMMENT
INVOICE_IDthe invoice number, not gapless
CUSTOMERwho it is for
AMOUNTgross, in account currency
ISSUEDNULL

The same four columns, the same three comments, the same NULL. This one comes back in the table's own column order rather than alphabetically.

And the stored definition carries them as well.

Query
SELECT GET_DDL('TABLE', 'INVOICES_T112') AS THE_DDL;
Result1 row · 1 column
THE_DDL
create or replace TABLE INVOICES_T112 ( INVOICE_ID NUMBER(38,0) COMMENT 'the invoice number, not gapless', CUSTOMER VARCHAR(40) COMMENT 'who it is for', AMOUNT NUMBER(10,2) COMMENT 'gross, in account currency', ISSUED DATE )COMMENT='episode 112 probe table' ;

GET_DDL writes each comment back into the column that owns it, and the table's own comment onto the end. If you are copying a table definition somewhere else, this is the version that takes the comments with it.

Let's add a comment after the fact

A comment is not something you have to decide at create time. COMMENT ON COLUMN sets one on a column that already exists.

Query
COMMENT ON COLUMN INVOICES_T112.ISSUED IS 'the date on the paper, not the date we entered it';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT COLUMN_NAME, COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'PUBLIC' AND TABLE_NAME = 'INVOICES_T112'
ORDER BY ORDINAL_POSITION;
Result4 rows · 2 columns
COLUMN_NAMECOMMENT
INVOICE_IDthe invoice number, not gapless
CUSTOMERwho it is for
AMOUNTgross, in account currency
ISSUEDthe date on the paper, not the date we entered it

Every column has one now. Nothing about the column itself changed, only the description of it.

The table's own comment can be changed the same way.

Query
COMMENT ON TABLE INVOICES_T112 IS 'episode 112 probe table - comment changed after the fact';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT TABLE_NAME, COMMENT
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC' AND TABLE_NAME = 'INVOICES_T112';
Result1 row · 2 columns
TABLE_NAMECOMMENT
INVOICES_T112episode 112 probe table - comment changed after the fact

Replaced, not appended. COMMENT ON always sets the whole thing.

Does a comment survive a change to the column?

This is the question that matters if you are relying on comments as documentation. Let's widen the amount column and see what happens to the comment on it.

Query
ALTER TABLE INVOICES_T112 ALTER COLUMN AMOUNT SET DATA TYPE NUMBER(12,2);
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT COLUMN_NAME, DATA_TYPE, NUMERIC_PRECISION, COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'PUBLIC' AND TABLE_NAME = 'INVOICES_T112'
  AND COLUMN_NAME = 'AMOUNT';
Result1 row · 4 columns
COLUMN_NAMEDATA_TYPENUMERIC_PRECISIONCOMMENT
AMOUNTNUMBER12gross, in account currency

The precision is the new one, and the comment is still there, word for word. It survived.

Now something more drastic. Let's rename the column we gave a comment to a minute ago.

Query
ALTER TABLE INVOICES_T112 RENAME COLUMN ISSUED TO ISSUE_DATE;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT COLUMN_NAME, COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'PUBLIC' AND TABLE_NAME = 'INVOICES_T112'
ORDER BY ORDINAL_POSITION;
Result4 rows · 2 columns
COLUMN_NAMECOMMENT
INVOICE_IDthe invoice number, not gapless
CUSTOMERwho it is for
AMOUNTgross, in account currency
ISSUE_DATEthe date on the paper, not the date we entered it

Still there, under the new name. Comments follow the column rather than the name, so neither of those two changes lost anything.

What happens if we set a comment to an empty string?

There is no COMMENT OFF. The way people remove a comment is to set it to nothing, so let's see exactly what that leaves behind.

Query
COMMENT ON COLUMN INVOICES_T112.CUSTOMER IS '';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT COLUMN_NAME, COMMENT, LENGTH(COMMENT) AS COMMENT_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'PUBLIC' AND TABLE_NAME = 'INVOICES_T112'
  AND COLUMN_NAME = 'CUSTOMER';
Result1 row · 3 columns
COLUMN_NAMECOMMENTCOMMENT_LENGTH
CUSTOMER0

The comment cell is empty and its length is zero. That is an empty string, not a NULL. The column now has a comment, and the comment is nothing.

Compare it with ISSUED near the top of this post, which had a real NULL because nobody had ever written a comment on it. The two look the same to a person and completely different to a query.

Counting carelessly

If you are counting undocumented columns with WHERE COMMENT IS NULL, this column will not be in your answer. Test for both: COMMENT IS NULL OR COMMENT = ''.

And SHOW COLUMNS answers in JSON

There is a third way to ask what is in a table, and it replies in a shape nobody expects.

Query
SHOW COLUMNS IN TABLE INVOICES_T112;
Result4 rows · 13 columns · scroll →
table_nameschema_namecolumn_namedata_typenull?defaultkindexpressioncommentdatabase_nameautoincrementschema_evolution_recordwrite_default
INVOICES_T112PUBLICINVOICE_ID{"type":"FIXED","precision":38,"scale":0,"nullable":true}trueCOLUMNthe invoice number, not gaplessDEMO_DBNULLNULL
INVOICES_T112PUBLICCUSTOMER{"type":"TEXT","length":40,"byteLength":160,"nullable":true,"fixed":false}trueCOLUMNDEMO_DBNULLNULL
INVOICES_T112PUBLICAMOUNT{"type":"FIXED","precision":12,"scale":2,"nullable":true}trueCOLUMNgross, in account currencyDEMO_DBNULLNULL
INVOICES_T112PUBLICISSUE_DATE{"type":"DATE","nullable":true}trueCOLUMNthe date on the paper, not the date we entered itDEMO_DBNULLNULL

The comments are all correct, including the empty one we just made. Now look at the data_type column.

Query
SELECT "column_name", "data_type", "comment"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
ORDER BY "column_name";
Result4 rows · 3 columns
column_namedata_typecomment
AMOUNT{"type":"FIXED","precision":12,"scale":2,"nullable":true}gross, in account currency
CUSTOMER{"type":"TEXT","length":40,"byteLength":160,"nullable":true,"fixed":false}
INVOICE_ID{"type":"FIXED","precision":38,"scale":0,"nullable":true}the invoice number, not gapless
ISSUE_DATE{"type":"DATE","nullable":true}the date on the paper, not the date we entered it

That is JSON. AMOUNT comes back as {"type":"FIXED","precision":12,"scale":2,"nullable":true}, with the precision we widened it to. The date column has its own shorter object.

DESCRIBE told us the same fact as a single string, in the form a person writes it in a CREATE TABLE. SHOW COLUMNS tells us as an object, in the form a program would want it. Same fact, two commands, two shapes.

That is worth knowing before you write anything that parses one of them, because the two are not interchangeable and neither one is wrong.

One more: SHOW VIEWS, and what it quietly includes

We have one view in this schema. Let's see what SHOW VIEWS makes of it.

Query
SHOW VIEWS IN SCHEMA PUBLIC;
Result3 rows · 12 columns · scroll →
Scroll the grid sideways for the text column.
created_onnamereserveddatabase_nameschema_nameownercommenttextis_secureis_materializedowner_role_typechange_tracking
2026-09-28 18:27:18.637000-07:00BIG_INVOICES_T112DEMO_DBPUBLICACCOUNTADMINinvoices over 100CREATE OR REPLACE VIEW BIG_INVOICES_T112 comment = 'invoices over 100' AS SELECT INVOICE_ID, CUSTOMER, AMOUNT FROM INVOICES_T112 WHERE AMOUNT > 100falsefalseROLEOFF
2026-09-28 18:25:34.020000-07:00MV_CTE_T109DEMO_DBPUBLICACCOUNTADMINCREATE OR REPLACE MATERIALIZED VIEW MV_CTE_T109 AS WITH BIG AS (SELECT ORDER_ID, AMOUNT FROM ORDERS_T109 WHERE AMOUNT > 100) SELECT ORDER_ID, AMOUNT FROM BIGfalsetrueROLEOFF
2026-09-28 18:25:32.825000-07:00MV_UNIONED_T109DEMO_DBPUBLICACCOUNTADMINCREATE OR REPLACE MATERIALIZED VIEW MV_UNIONED_T109 AS SELECT ORDER_ID, AMOUNT FROM ORDERS_T109 WHERE REGION = 'north' UNION ALL SELECT ORDER_ID, AMOUNT FROM ORDERS_T109 WHERE REGION = 'south'falsetrueROLEOFF

Three rows, and we only made one view. The other two are materialized views, which SHOW VIEWS lists alongside ordinary ones, with is_materialized set to true to tell them apart.

They are left over from Episode 109. That episode predicted Snowflake would refuse to build a materialized view over a UNION ALL and over a WITH clause, and it accepted both, so no DROP was ever written for them. Their definitions are there in the text column if you want to read them.

Filtering down to the one this post made is the same trick as before.

Query
SELECT "name", "comment", "is_secure"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T112';
Result1 row · 3 columns
namecommentis_secure
BIG_INVOICES_T112invoices over 100false

One row, with its comment and the is_secure flag. The filter is a WHERE clause on the output of a SHOW, which is the thing we could not do at the start of this post.

So which command should you count with?

SHOW TABLES missed the view and the catalog found it. There is a third command that covers both, and it says which is which.

Query
SHOW OBJECTS IN SCHEMA PUBLIC;
Result16 rows · 16 columns · scroll →
Every object in the schema, tables and views together.
created_onnamedatabase_nameschema_namekindcommentcluster_byrowsbytesownerretention_timeowner_role_typeis_hybridis_dynamicis_icebergis_interactive
2026-09-28 18:27:18.637000-07:00BIG_INVOICES_T112DEMO_DBPUBLICVIEWinvoices over 10000ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:08.999000-07:00CUSTOMERSDEMO_DBPUBLICTABLE101536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:07.395000-07:00DEPARTMENTSDEMO_DBPUBLICTABLE41024ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:15.165000-07:00DOCS_XMLDEMO_DBPUBLICTABLE41536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:08.115000-07:00EMPLOYEESDEMO_DBPUBLICTABLE82048ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:11.646000-07:00EVENTS_JSONDEMO_DBPUBLICTABLE43072ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:17.808000-07:00INVOICES_T112DEMO_DBPUBLICTABLEepisode 112 probe table - comment changed after the fact31024ACCOUNTADMIN1ROLENNNN
2026-09-27 03:50:28.146000-07:00JSON_LOADEDDEMO_DBPUBLICTABLE112560ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:14.430000-07:00JSON_TEXT_RAWDEMO_DBPUBLICTABLE111536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:25:34.020000-07:00MV_CTE_T109DEMO_DBPUBLICVIEW21024ACCOUNTADMIN1ROLENNNN
2026-09-28 18:25:32.825000-07:00MV_UNIONED_T109DEMO_DBPUBLICVIEW41024ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:09.808000-07:00ORDERSDEMO_DBPUBLICTABLE411536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112DEMO_DBPUBLICTABLE00ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:10.959000-07:00SALES_RAWDEMO_DBPUBLICTABLE81536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:16.148000-07:00TYPED_SHAPESDEMO_DBPUBLICTABLE22560ACCOUNTADMIN1ROLENNNN
2026-09-27 20:10:07.808000-07:00XML_LOADEDDEMO_DBPUBLICTABLE44096ACCOUNTADMIN1ROLENNNN

Everything in the schema, in one list, with a kind column saying what each one is. The flags on the end — is_hybrid, is_dynamic, is_iceberg — name the special kinds of table, which is how you tell a dynamic table from an ordinary one without reading IS_INSERTABLE_INTO.

Have a look at the comment column on the rows that have none. SHOW OBJECTS reports an empty string, the same as SHOW TABLES did.

Now let's count by kind.

Query
SELECT "kind", COUNT(*) AS HOW_MANY
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T112'
GROUP BY "kind"
ORDER BY "kind";
Result2 rows · 2 columns
kindHOW_MANY
TABLE2
VIEW1

Two tables and one view, which is the answer the catalog gave us and the answer SHOW TABLES did not.

And since it is a table, we can have the whole summary in one row.

Run this first
SHOW OBJECTS IN SCHEMA PUBLIC;
Result16 rows · 16 columns · scroll →
created_onnamedatabase_nameschema_namekindcommentcluster_byrowsbytesownerretention_timeowner_role_typeis_hybridis_dynamicis_icebergis_interactive
2026-09-28 18:27:18.637000-07:00BIG_INVOICES_T112DEMO_DBPUBLICVIEWinvoices over 10000ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:08.999000-07:00CUSTOMERSDEMO_DBPUBLICTABLE101536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:07.395000-07:00DEPARTMENTSDEMO_DBPUBLICTABLE41024ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:15.165000-07:00DOCS_XMLDEMO_DBPUBLICTABLE41536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:08.115000-07:00EMPLOYEESDEMO_DBPUBLICTABLE82048ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:11.646000-07:00EVENTS_JSONDEMO_DBPUBLICTABLE43072ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:17.808000-07:00INVOICES_T112DEMO_DBPUBLICTABLEepisode 112 probe table - comment changed after the fact31024ACCOUNTADMIN1ROLENNNN
2026-09-27 03:50:28.146000-07:00JSON_LOADEDDEMO_DBPUBLICTABLE112560ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:14.430000-07:00JSON_TEXT_RAWDEMO_DBPUBLICTABLE111536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:25:34.020000-07:00MV_CTE_T109DEMO_DBPUBLICVIEW21024ACCOUNTADMIN1ROLENNNN
2026-09-28 18:25:32.825000-07:00MV_UNIONED_T109DEMO_DBPUBLICVIEW41024ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:09.808000-07:00ORDERSDEMO_DBPUBLICTABLE411536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:18.914000-07:00PAYMENTS_T112DEMO_DBPUBLICTABLE00ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:10.959000-07:00SALES_RAWDEMO_DBPUBLICTABLE81536ACCOUNTADMIN1ROLENNNN
2026-09-28 18:27:16.148000-07:00TYPED_SHAPESDEMO_DBPUBLICTABLE22560ACCOUNTADMIN1ROLENNNN
2026-09-27 20:10:07.808000-07:00XML_LOADEDDEMO_DBPUBLICTABLE44096ACCOUNTADMIN1ROLENNNN
Query
SELECT COUNT(*)                                        AS OBJECTS_FROM_THIS_FILE,
       SUM(IFF("kind" = 'TABLE', 1, 0))                AS TABLES,
       SUM(IFF("kind" = 'VIEW', 1, 0))                 AS VIEWS,
       SUM(IFF("comment" IS NULL OR "comment" = '', 1, 0)) AS WITHOUT_A_COMMENT
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T112';
Result1 row · 4 columns
OBJECTS_FROM_THIS_FILETABLESVIEWSWITHOUT_A_COMMENT
3211

Objects, tables, views and the number of them with no useful comment, worked out in one statement over the output of a SHOW. The last column counts a NULL and an empty string together on purpose, which after the last two sections is the only honest way to count it.

One last thing: let's tidy up

The view goes first, because it reads from the table.

Cleanup
-- Put the schema back the way we found it.
DROP VIEW  IF EXISTS BIG_INVOICES_T112;
DROP TABLE IF EXISTS INVOICES_T112;
DROP TABLE IF EXISTS PAYMENTS_T112;
Query
SELECT CURRENT_DATABASE()                 AS THE_DATABASE,
       CURRENT_SCHEMA()                   AS THE_SCHEMA,
       (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES
        WHERE RIGHT(TABLE_NAME, 5) = '_T112') AS PROBE_OBJECTS_LEFT,
       (SELECT COUNT(*) FROM CUSTOMERS)   AS DEMO_DB_IS_READABLE;
Result1 row · 4 columns
THE_DATABASETHE_SCHEMAPROBE_OBJECTS_LEFTDEMO_DB_IS_READABLE
DEMO_DBPUBLIC010

No probe objects left, and the demo database still reads. Back where we started.

Key points

  • A WHERE clause on a SHOW is a syntax error, and so is selecting from one. Its own LIKE is the only filter it has.
  • TABLE(RESULT_SCAN(LAST_QUERY_ID())) turns the last query's output into a table, so a SHOW can be filtered, counted, summed, sorted and joined.
  • SHOW returns its column names in lower case, so they have to be written in double quotes.
  • SHOW TABLES and INFORMATION_SCHEMA.TABLES disagree, because the catalog view includes views and SHOW TABLES does not.
  • SHOW OBJECTS covers both and has a kind column that says which is which.
  • DESCRIBE returns one row per column and a very wide grid to say it in. DESC is the same command.
  • DESCRIBE VIEW works on a table. The two keywords are interchangeable there.
  • DESCRIBE RESULT LAST_QUERY_ID() gives the types a query produced, including for expressions you never declared.
  • A NUMBER(10,2) multiplied by 1.2 came back as NUMBER(12,3), which is written nowhere in the query.
  • A column comment survives a type change and survives a rename. Both held.
  • Setting a comment to '' leaves an empty string, not a NULL. Test for both when you count undocumented columns.
  • A missing comment comes back as an empty string from SHOW and as a NULL from the catalog view. Same fact, two answers.
  • SHOW COLUMNS reports the data type as a JSON object where DESCRIBE reports it as a string.
  • SHOW VIEWS lists materialized views too, with is_materialized set to true.
Next in this series

Episode 113 — external tables and Iceberg tables. Both of them want cloud storage, and the account in these posts has none. So instead of describing them we will ask Snowflake, and read the refusals, which turn out to be the clearest definition of either feature you will get.

Every query and every result grid on this page was captured from a live Snowflake account (version 10.34.101) running the demo script for this episode, and the sections are in the order the script ran them, so the grids agree with the text beside them. The _T112 objects are created and dropped by the scripts above. Other objects in the grids belong to earlier posts in this series, including two materialized views Episode 109 left behind, and the text says so where they appear. Empty cells marked empty are empty strings and cells reading NULL are real nulls; the difference is a point this post makes twice. Nothing is timed and no performance claims are made anywhere in this series. RESULT_SCAN follows the Snowflake RESULT_SCAN documentation.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.