简体   繁体   English

为什么 BigQuery 不允许我的正则表达式在 Postgres 中运行?

[英]Why doesn't BigQuery allow my regex that works in Postgres?

I'm running the following query against a Postgres DB:我正在针对 Postgres 数据库运行以下查询:

SUBSTRING(my_col, '[0-9\-]+') AS extracted_string

Which works fine and extracts the sequence I want, but when I run the equivalent BigQuery query:哪个工作正常并提取我想要的序列,但是当我运行等效的 BigQuery 查询时:

REGEXP_EXTRACT(my_col, '[0-9\-]+') AS extracted_string

It throws an exception saying:它抛出一个异常说:

Syntax error: Illegal escape sequence: \\-

You have to specify that your regex strings are in fact regex strings and should be treated differently in BigQuery.您必须指定您的正则表达式字符串实际上是正则表达式字符串,并且应该在 BigQuery 中区别对待。

The fix is to place the r character in front of your regex string like so:解决方法是将r字符放在您的正则表达式字符串前面,如下所示:

REGEXP_EXTRACT(my_col, r'[0-9\-]+') AS extracted_string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BigQuery 查询不适用于 UNNEST() - BigQuery query doesn't work with UNNEST() 为什么 AngularFire 不返回我的 Firestore 集合中的最新数据? - Why doesn't AngularFire return the latest data in my Firestore collection? GCP Cloud Function 将数据写入 BigQuery 运行成功,但数据未出现在 BigQuery 表中 - GCP Cloud Function to write data to BigQuery runs with success but data doesn't appear in BigQuery table 为什么我的 hashmap 没有被添加到 firebase 实时数据库中? - Why doesn't my hashmap get added to firebase realtime database? 云 API 网关不允许 CORS - Cloud API Gateway doesn't allow with CORS Google Analytics 4 BigQuery 链接:事件排除不起作用 - Google Analytics 4 BigQuery Link: Event exclusion doesn't work 使用 docker 组合的 Golang 项目和 postgres 图像不会失败,但也不起作用 - Golang project and postgres image with docker compose up doesn't fail, but doesn't work either BigQuery 中的简单正则表达式匹配不起作用 - Simple regex matching in BigQuery not working Crashlytics 适用于生产但不适用于测试 - Crashlytics works on production but doesn't work on test BigQuery 不允许在删除后添加列 - BigQuery does not allow adding columns after dropping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM