1

PostgreSQL 9.5.4

I have the below function where I am attempting to use the parameters within the Regex. Something like

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;

The returned error is:

ERROR: argument of WHERE must be type boolean, not type text LINE 55: where t.lastname ~* '^' || $1 || ''

How is this done?

TIA

1 Answer 1

6

You need to put the concatenation between parentheses (and you can remove the empty string at the end:

where t.lastname ~*  ('^' || $1) 

alternatively:

where t.lastname ~*  concat('^', $1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.