quote_literal with NULL

Поиск
Список
Период
Сортировка
От Brendan Jurd
Тема quote_literal with NULL
Дата
Msg-id 37ed240d0710092157t5f56ecfai24b93b3cf31718c7@mail.gmail.com
обсуждение исходный текст
Ответы Re: quote_literal with NULL  (Simon Riggs <simon@2ndquadrant.com>)
Список pgsql-hackers
Hi hackers,

I note that if you pass NULL to quote_literal(), you get NULL.

This isn't surprising, but I was thinking that the stated purpose of
quote_literal is preparing the argument for entry into a dynamic SQL
statement.  In this context, it fails for NULL input.

Wouldn't it be more useful if quote_literal(NULL) yielded the text value 'NULL'?

With the current behaviour, if you want quote_literal to be "null
safe" you have to replace any such calls with
coalesce(quote_literal(foo), 'NULL')).  Since the use case for
quote_literal is concatenating the result with some other text, a NULL
return seems guaranteed to be unhelpful.

Meanwhile, the string 'NULL' is the only way of representing a NULL in
SQL, so it makes sense (to me) that this is what quote_literal should
output.

Comments?

Cheers,
BJ


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

Предыдущее
От: Euler Taveira de Oliveira
Дата:
Сообщение: Re: [COMMITTERS] pgsql: Added the Skytools extended transaction ID module to contrib as
Следующее
От: "Pavel Stehule"
Дата:
Сообщение: Re: some points for FAQ