从postgres中的文本字符串中提取子字符串
Extract a substring from a text string in postgres
我正在尝试从 postgresql 中的文本字符串中提取子字符串。文本字符串的列名是 URL,我正在使用 subtring 函数定义一个正则表达式,它将 return 只有我想要的部分:
SELECT
substring('user_latitude=.*user_' from URL)
FROM my_table
limit 10
当我执行此查询时,收到以下响应:
SQL Error [XX000]: ERROR: Not implemented
Detail:
error: Not implemented
code: 1001
context: 'false' - Function substring(text,text) not implemented - use REGEXP_SUBSTR instead
query: 258128
location: cg_expr.cpp:4265
process: padbmaster [pid=52019]
org.postgresql.util.PSQLException: ERROR: Not implemented
Detail:
error: Not implemented
code: 1001
context: 'false' - Function substring(text,text) not implemented - use >REGEXP_SUBSTR instead
query: 258128
location: cg_expr.cpp:4265
process: padbmaster [pid=52019]
但是,REGEXP_SUBSTR 似乎不是本机函数,也不起作用。
有没有办法从 POSTGRES 中的字符串中提取值?
谢谢
由于您使用的 Amazon Redshift 运行 是基于 Postgres 8.0.2 构建的,而且还有很多 Postgres 函数 is not supported, it is good to take a look at the documentation 以查看实际可用的内容。
SUBSTRING 函数的签名与您使用它的方式不同,它应该是这样的:
select
substring(URL from 14)
from my_table
limit 10
这将产生 URL
从第 14 个字符到结尾的部分。
或者,如果甚至不支持此版本的 SUBSTRING,请尝试使用建议的 REGEXP_SUBSTR:
select
regexp_substr(URL, '=.*')
from my_table
limit 10
这将 return URL
从“=”开始的部分。
我正在尝试从 postgresql 中的文本字符串中提取子字符串。文本字符串的列名是 URL,我正在使用 subtring 函数定义一个正则表达式,它将 return 只有我想要的部分:
SELECT
substring('user_latitude=.*user_' from URL)
FROM my_table
limit 10
当我执行此查询时,收到以下响应:
SQL Error [XX000]: ERROR: Not implemented Detail:
error: Not implemented code: 1001 context: 'false' - Function substring(text,text) not implemented - use REGEXP_SUBSTR instead query: 258128 location: cg_expr.cpp:4265 process: padbmaster [pid=52019]
org.postgresql.util.PSQLException: ERROR: Not implemented Detail:
error: Not implemented code: 1001 context: 'false' - Function substring(text,text) not implemented - use >REGEXP_SUBSTR instead query: 258128 location: cg_expr.cpp:4265 process: padbmaster [pid=52019]
但是,REGEXP_SUBSTR 似乎不是本机函数,也不起作用。
有没有办法从 POSTGRES 中的字符串中提取值?
谢谢
由于您使用的 Amazon Redshift 运行 是基于 Postgres 8.0.2 构建的,而且还有很多 Postgres 函数 is not supported, it is good to take a look at the documentation 以查看实际可用的内容。
SUBSTRING 函数的签名与您使用它的方式不同,它应该是这样的:
select
substring(URL from 14)
from my_table
limit 10
这将产生 URL
从第 14 个字符到结尾的部分。
或者,如果甚至不支持此版本的 SUBSTRING,请尝试使用建议的 REGEXP_SUBSTR:
select
regexp_substr(URL, '=.*')
from my_table
limit 10
这将 return URL
从“=”开始的部分。