Re: Directly embedding a psql SET variable inside another string?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Ron <ronljohnsonjr(at)gmail(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Directly embedding a psql SET variable inside another string?
Date: 2023-01-13 17:13:36
Message-ID: CAKFQuwaj1xXH6gA=eqJp7JmwF3GzDwBSRLzqmedycL80EnwGQg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jan 13, 2023 at 9:12 AM Ron <ronljohnsonjr(at)gmail(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2023-01-13 17:13:59 Re: Directly embedding a psql SET variable inside another string?
Previous Message Adam Scott 2023-01-13 17:08:16 Re: Directly embedding a psql SET variable inside another string?