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

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: "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 18:07:25
Message-ID: 76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/13/23 11:13, David G. Johnston wrote:
> 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')

This one looks clean, and works perfectly:

> '%' || :'v_ssn' || '%'

--
Born in Arizona, moved to Babylonia.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ken Tanzer 2023-01-13 22:17:48 Re: Intervals and ISO 8601 duration
Previous Message David G. Johnston 2023-01-13 17:14:45 Re: Directly embedding a psql SET variable inside another string?