From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "George Weaver" <gweaver(at)shaw(dot)ca> |
Cc: | "pgsql-general" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Problem Using RowType Declaration with Table Domains |
Date: | 2010-06-22 04:26:05 |
Message-ID: | 23370.1277180765@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"George Weaver" <gweaver(at)shaw(dot)ca> writes:
> I have the following (very simplified) scenario:
> CREATE DOMAIN orderstatus AS text NOT NULL DEFAULT 'Open';
> CREATE TABLE orders ( orderno serial
> , status orderstatus
> , PRIMARY KEY (orderno));
> CREATE OR REPLACE FUNCTION getOrder(int4)
> RETURNS
> orders
> AS
> $$DECLARE
> orderno_in alias for $1;
> saleorder orders%rowtype;
> ...
> test1=# select * from getorder(3);
> ERROR: domain orderstatus does not allow null values
> CONTEXT: PL/pgSQL function "getorder" line 4 during statement block local
> variable initialization
> Is there a way around this?
I think you've just hit one of the many reasons why declaring domains
with NOT NULL constraints is a bad idea. If you are utterly wedded to
doing that, you can assign an initial value to the "saleorder" variable
that sets saleorder.status to a valid non-null value. But be prepared
for more pain in the future, and more pain after that. (Hint: what do
you expect a LEFT JOIN to the orders table to produce?) NOT NULL domain
constraints may perhaps not have been the SQL committee's worst idea
ever, but they're definitely in the top ten.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2010-06-22 05:08:48 | Re: No PL/PHP ? Any reason? |
Previous Message | Gerd Koenig | 2010-06-22 04:25:42 | Re: Trying to install ODBC driver on Windows XP notebook |