选择非特定类型的列 SQL
selecting columns which are NOT of a specific type SQL
我想select BigQuery 中所有非“TIMESTAMP”类型的列。我写了查询,其中 returns 这样的列是:
SELECT COLUMN_NAME
FROM d1.INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 't1' AND
DATA_TYPE != 'TIMESTAMP'
但我正在努力从 SQL 中的这些列中获取 return 数据,我尝试了以下查询,结果是“标量子查询产生了多个元素”。
SELECT (
SELECT COLUMN_NAME
FROM d1.INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 't1' AND
DATA_TYPE != 'TIMESTAMP'
) from `d1.t1`;
谁能帮我从 table 't1' 中获取数据类型!=TIMESTAMP 的列?感谢您的期待!
在评论部分应用@Mikhail 的建议,您可以尝试这个查询:
BEGIN
DECLARE col_not_tmstmp STRING;
-- putting the result of your query into a variable
SET col_not_tmstmp = (SELECT STRING_AGG(COLUMN_NAME)
FROM <your-project>.<your-dataset>.INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = '<your_table>' AND
DATA_TYPE != 'TIMESTAMP');
-- use execute immediate to apply the variable to main query
EXECUTE IMMEDIATE FORMAT ("""
SELECT %s
FROM `<your-project>.<your-dataset>.<your_table>`
""", col_not_tmstmp
);
END
Table:
输出:
我想select BigQuery 中所有非“TIMESTAMP”类型的列。我写了查询,其中 returns 这样的列是:
SELECT COLUMN_NAME
FROM d1.INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 't1' AND
DATA_TYPE != 'TIMESTAMP'
但我正在努力从 SQL 中的这些列中获取 return 数据,我尝试了以下查询,结果是“标量子查询产生了多个元素”。
SELECT (
SELECT COLUMN_NAME
FROM d1.INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 't1' AND
DATA_TYPE != 'TIMESTAMP'
) from `d1.t1`;
谁能帮我从 table 't1' 中获取数据类型!=TIMESTAMP 的列?感谢您的期待!
在评论部分应用@Mikhail 的建议,您可以尝试这个查询:
BEGIN
DECLARE col_not_tmstmp STRING;
-- putting the result of your query into a variable
SET col_not_tmstmp = (SELECT STRING_AGG(COLUMN_NAME)
FROM <your-project>.<your-dataset>.INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = '<your_table>' AND
DATA_TYPE != 'TIMESTAMP');
-- use execute immediate to apply the variable to main query
EXECUTE IMMEDIATE FORMAT ("""
SELECT %s
FROM `<your-project>.<your-dataset>.<your_table>`
""", col_not_tmstmp
);
END
Table:
输出: