Re: Directly embedding a psql SET variable inside another string? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Directly embedding a psql SET variable inside another string?
Date
Msg-id CAKFQuwaj1xXH6gA=eqJp7JmwF3GzDwBSRLzqmedycL80EnwGQg@mail.gmail.com
Whole thread Raw
In response to Directly embedding a psql SET variable inside another string?  (Ron <ronljohnsonjr@gmail.com>)
Responses Re: Directly embedding a psql SET variable inside another string?
List pgsql-general
On Fri, Jan 13, 2023 at 9:12 AM Ron <ronljohnsonjr@gmail.com> wrote:

is there any way to directly embed v_ssn in another string?

No
As expected, this fails:

postgres=# SELECT * FROM employee WHERE ssn LIKE :'%v_ssn%';
ERROR:  syntax error at or near ":"
LINE 1: SELECT * FROM employee WHERE ssn LIKE :'%v_ssn%';


Two options:

format('%%%s%%', :'v_ssn')
'%' || :'v_ssn' || '%'

David J.

pgsql-general by date:

Previous
From: Adam Scott
Date:
Subject: Re: Directly embedding a psql SET variable inside another string?
Next
From: Adrian Klaver
Date:
Subject: Re: Directly embedding a psql SET variable inside another string?