在 CTE returns 中显示列错误 - 为什么?

show columns in CTE returns an error - why?

我有一个工作正常的显示列查询:

SHOW COLUMNS IN table

但是尝试将其放入 CTE 时失败,如下所示:

WITH columns_table AS (
SHOW COLUMNS IN table
)

SELECT * from columns_table

知道为什么以及如何解决它吗?

CTE 需要 select 子句,我们不能使用 SHOW COLUMN IN CTE 作为替代方法使用 INFORMATION_SCHEMA 来检索元数据。如下所示:

WITH columns_table AS (
Select * from INTL_DB.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='CURRENCIES'
)
SELECT * from columns_table;

使用RESULT_SCAN

Returns the result set of a previous command (within 24 hours of when you executed the query) as if the result was a table. This is particularly useful if you want to process the output from any of the following:

SHOW or DESC[RIBE] command that you executed.

SHOW COLUMNS IN ...;

WITH columns_table AS (
   SELECT *
   FROM table(RESULT_SCAN(LAST_QUERY_ID()))
)
SELECT *
FROM columns_table;