【发布时间】:2020-06-10 18:51:40
【问题描述】:
我正在尝试解析存储在表列中的以下 sql 查询创建、插入或更新的表。
我们将表格列称为query。以下是一些示例数据,用于展示数据的外观变化。
with sample_data as (
select 1 as id, 'CREATE TABLE tbl1 ...' as query union all
select 2 as id, 'CREATE OR REPLACE TABLE tbl1 ...' as query union all
select 3 as id, 'DROP TABLE IF EXISTS tbl1; CREATE TABLE tbl1 ...' as query union all
select 4 as id, 'INSERT /*some comment*/ INTO tbl2 ...' as query union all
select 5 as id, 'INSERT /*some comment*/ INTO tbl2 ...' as query union all
select 6 as id, 'UPDATE tbl3 SET col1 = ...' as query union all
select 7 as id, '/*some garbage comments*/ UPDATE tbl3 SET col1 = ...' as query union all
select 8 as id, 'DELETE tbl4 ...' as query
),
以下是查询的格式(我们正在尝试提取 table_name):
#1
some optional statements like drop table
创建some comments or optional statement like OR REPLACE 表table_name
everything else
#2
some optional statements like drop table
插入some comments 插入some comments table_name
#3
some optional statements like drop table
更新some comments table_name
everything else
【问题讨论】:
-
“我是”,“我们是”?到目前为止,您/您尝试了什么?你在哪里失败了?
-
我的正则表达式经验仅限于 LIKE '%%' 语句。你能帮忙吗?
-
SQL 和它的 LIKE 运算符都不是正则表达式。 Stack Overflow 用于征求建议,而不是委派要完成的工作。你甚至没有解决问题。
-
那么根据显示的数据,预期的输出是什么?
标签: sql regex parsing google-bigquery data-extraction