quote_literal with NULL

From: "Brendan Jurd" <direvus(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: quote_literal with NULL
Date: 2007-10-10 04:57:01
Message-ID: 37ed240d0710092157t5f56ecfai24b93b3cf31718c7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2007-10-10 05:04:56 Re: some points for FAQ
Previous Message Euler Taveira de Oliveira 2007-10-10 04:14:56 Re: [COMMITTERS] pgsql: Added the Skytools extended transaction ID module to contrib as

Browse pgsql-patches by date

  From Date Subject
Next Message Peter Eisentraut 2007-10-10 07:07:55 Re: Provide a way to not ask for a password in psql
Previous Message Euler Taveira de Oliveira 2007-10-10 01:38:47 Re: Provide a way to not ask for a password in psql