quote_literal with NULL - Mailing list pgsql-hackers

From Brendan Jurd
Subject quote_literal with NULL
Date
Msg-id 37ed240d0710092157t5f56ecfai24b93b3cf31718c7@mail.gmail.com
Whole thread Raw
Responses Re: quote_literal with NULL
List 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 by date:

Previous
From: Euler Taveira de Oliveira
Date:
Subject: Re: [COMMITTERS] pgsql: Added the Skytools extended transaction ID module to contrib as
Next
From: "Pavel Stehule"
Date:
Subject: Re: some points for FAQ