[英]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.