雪花中的批量列 DROP --- WHERE 列的第一个字符的语法 LIKE '_'

Bulk column DROP in snowflake --- syntax for WHERE first character of column LIKE '_'

Snowflake table 已填充了 2000 多列,因为每个 属性 都作为 KEY 而不是 VALUE 发送。

需要删除这些列。

它们都以 _ 开头,例如'_ASD3234E2

为了测试我的语法对于最终的 ALTER TABLE 命令是否正确,我首先尝试 SHOW COLUMNS 命令。

SHOW COLUMNS LIKE '_%' IN TABLE DELIVERY_VIEW_DETAIL;

这显示了 table 中的所有列。

正如@Austin 提到的那样,它需要转义 -

SHOW COLUMNS LIKE '\_%' IN TABLE TRANS_1 ;
+------------+-------------+-------------+
| table_name | schema_name | column_name |
|------------+-------------+-------------+
| TRANS_1    | PUBLIC      | _COL1       |
| TRANS_1    | PUBLIC      | _COL2       |
| TRANS_1    | PUBLIC      | _COL3       |
| TRANS_1    | PUBLIC      | _COL4       |
+------------+-------------+-------------+

没有越狱 -

SHOW COLUMNS LIKE '_%' IN TABLE TRANS_1 ;
+------------+-------------+-------------+
| table_name | schema_name | column_name |
|------------+-------------+-------------+
| TRANS_1    | PUBLIC      | ID          |
| TRANS_1    | PUBLIC      | _COL1       |
| TRANS_1    | PUBLIC      | _COL2       |
| TRANS_1    | PUBLIC      | _COL3       |
| TRANS_1    | PUBLIC      | _COL4       |
+------------+-------------+-------------+

单次转义-

SHOW COLUMNS LIKE '\_%' IN TABLE TRANS_1 ;
+------------+-------------+-------------+
| table_name | schema_name | column_name |
|------------+-------------+-------------+
| TRANS_1    | PUBLIC      | ID          |
| TRANS_1    | PUBLIC      | _COL1       |
| TRANS_1    | PUBLIC      | _COL2       |
| TRANS_1    | PUBLIC      | _COL3       |
| TRANS_1    | PUBLIC      | _COL4       |
+------------+-------------+-------------+

所有列 -

SHOW COLUMNS IN TABLE TRANS_1 ;
+------------+-------------+-------------+
| table_name | schema_name | column_name |
|------------+-------------+-------------+
| TRANS_1    | PUBLIC      | ID          |
| TRANS_1    | PUBLIC      | _COL1       |
| TRANS_1    | PUBLIC      | _COL2       |
| TRANS_1    | PUBLIC      | _COL3       |
| TRANS_1    | PUBLIC      | _COL4       |
+------------+-------------+-------------+