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

Поиск
Список
Период
Сортировка
От Ron
Тема Re: Directly embedding a psql SET variable inside another string?
Дата
Msg-id 76773204-7c6c-32ba-3dd9-4014267bce26@gmail.com
обсуждение исходный текст
Ответ на Re: Directly embedding a psql SET variable inside another string?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
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.

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Directly embedding a psql SET variable inside another string?
Следующее
От: Ken Tanzer
Дата:
Сообщение: Re: Intervals and ISO 8601 duration