Re: Data Loss from SQL SELECT (vs. COPY/pg_dump)

From: Kong Man <kong_mansatiansin(at)hotmail(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Data Loss from SQL SELECT (vs. COPY/pg_dump)
Date: 2013-04-05 22:51:38
Message-ID: DUB116-W175B9735F113E336895E098BDA0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

This seems to answer my question. I completely forgot about the behavior of NULL value in the text concatenation.

http://www.postgresql.org/docs/9.1/static/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE

Because quote_literal is labelled STRICT, it
will always return null when called with a null argument. In the above example,
if newvalue or keyvalue were null, the
entire dynamic query string would become null, leading to an error from EXECUTE. You
can avoid this problem by using the quote_nullable function,
which works the same as quote_literal except that
when called with a null argument it returns the string NULL. For
example,

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bhanu Murthy 2013-04-10 18:06:32 Encrypting PGBouncer to Postgres DB connections
Previous Message Kong Man 2013-04-05 19:56:16 Data Loss from SQL SELECT (vs. COPY/pg_dump)