Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 在PostgreSQL中使用带变量的正则表达式的正确语法_Regex_Postgresql - Fatal编程技术网

Regex 在PostgreSQL中使用带变量的正则表达式的正确语法

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

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.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)