Re: plpgsql allowing null fields in insert commands?

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Celia McInnis <celia(at)drmath(dot)ca>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: plpgsql allowing null fields in insert commands?
Date: 2005-03-16 14:07:59
Message-ID: 20050316060521.E47369@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, 15 Mar 2005, Celia McInnis wrote:

> In a plpgsql procedure is there any way to form an insert command which has
> some null values for values of the inputs?
>
> Currently when I form such a command, the command becomes null if there are
> any null values inserted for the fields.

Are you making a query string for execute?
Something like:
querystring := 'insert into foo(col1) values (' || variable || ')';
won't work if variable is null. You'd probably need something like:
querystring := 'insert into foo(col1) values (' ||
COALESCE(variable,'NULL') || ')';

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Greg Lindstrom 2005-03-16 17:31:39 XML and Postgres
Previous Message John DeSoi 2005-03-16 13:08:18 Re: plpgsql allowing null fields in insert commands?