pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Directly embedding a psql SET variable inside another string?
Date: Fri, 13 Jan 2023 12:07:25 -0600
Message-ID: <76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com> (raw)
In-Reply-To: <CAKFQuwaj1xXH6gA=eqJp7JmwF3GzDwBSRLzqmedycL80EnwGQg@mail.gmail.com>
References: <e556cfc8-30e6-014c-264a-f0b62d71a368@gmail.com>
	<CAKFQuwaj1xXH6gA=eqJp7JmwF3GzDwBSRLzqmedycL80EnwGQg@mail.gmail.com>

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

This one looks clean, and works perfectly:

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

-- 
Born in Arizona, moved to Babylonia.

view thread (6+ messages)

Message-ID: <76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com>
Permalink:  ../76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com/
Also on:    postgresql.org/message-id/76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Directly embedding a psql SET variable inside another string?
  In-Reply-To: <76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com>
  References: <e556cfc8-30e6-014c-264a-f0b62d71a368@gmail.com> <CAKFQuwaj1xXH6gA=eqJp7JmwF3GzDwBSRLzqmedycL80EnwGQg@mail.gmail.com> <76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox