Regex 在PostgreSQL中使用带变量的正则表达式的正确语法
PostgreSQL 9.5.4 我在下面的函数中尝试使用正则表达式中的参数。差不多Regex 在PostgreSQL中使用带变量的正则表达式的正确语法,regex,postgresql,Regex,Postgresql,PostgreSQL 9.5.4 我在下面的函数中尝试使用正则表达式中的参数。差不多 CREATE OR REPLACE FUNCTION test(lastname text, firstname text, birthdate date) RETURNS SETOF view_patient AS $BODY$ select * from testing t where t.lastname ~* '^' || $1 || '' order by t.lastna
CREATE OR REPLACE FUNCTION test(lastname text, firstname text, birthdate date)
RETURNS SETOF view_patient AS
$BODY$
select * from testing t
where t.lastname ~* '^' || $1 || ''
order by t.lastname
$BODY$
LANGUAGE sql VOLATILE;
返回的错误为:
错误:WHERE的参数必须是布尔类型,而不是文本行55的类型:
其中t.lastname~*'^'| |$1| |''
这是怎么做到的
TIA您需要将连接放在括号之间(您可以删除结尾处的空字符串:
where t.lastname ~* ('^' || $1)
或者:
where t.lastname ~* concat('^', $1)
您需要将连接放在括号之间(您可以删除结尾处的空字符串:
where t.lastname ~* ('^' || $1)
或者:
where t.lastname ~* concat('^', $1)