Search Postgresql Archives

Re: Problem Using RowType Declaration with Table Domains

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"George Weaver" <gweaver@xxxxxxx> 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux