[fwd: [GENERAL] Domains and function]

From: elein <elein(at)varlena(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: elein <elein(at)varlena(dot)com>
Subject: [fwd: [GENERAL] Domains and function]
Date: 2003-12-04 01:33:34
Message-ID: 20031203173334.D14660@cookie.varlena.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I did not get any response to this question on
general so I am forwarding it to hackers.

Thanks,

elein

----- Forwarded message from elein <elein(at)varlena(dot)com> -----

Date: Sat, 29 Nov 2003 14:11:20 -0800
From: elein <elein(at)varlena(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: elein <elein(at)varlena(dot)com>
Subject: [GENERAL] Domains and function
Mail-Followup-To: pgsql-general(at)postgresql(dot)org
User-Agent: Mutt/1.3.22.1i
Precedence: bulk

I can create a function with a domain and
define it to return a domain.

The parameter is checked to see if it qualifies
in the constraint of the domain, however, the
return value is not.

Is this a bug? Or is the author of the function
responsible for re-inforcing the constraint
at runtime?

This is the test case in 7.4:

=# create domain one2hundred AS integer
-# DEFAULT '1' CONSTRAINT email_domain check( VALUE > 0 AND VALUE <=100 );
CREATE DOMAIN
=#
=# create function gb52_add( one2hundred )
-# returns one2hundred as
-# '
'# BEGIN
'# RETURN $1 + 10;
'# END;
'# ' language 'plpgsql';
CREATE FUNCTION
=#
=# select gb52_add( 80);
gb52_add
----------
90
(1 row)

=# select gb52_add( 100);
gb52_add
----------
110
(1 row)

=# select gb52_add( 90);
gb52_add
----------
100
(1 row)

=# select gb52_add( 91);
gb52_add
----------
101
(1 row)

=# select gb52_add( 191);
ERROR: value for domain one2hundred violates check constraint "email_domain"

============================================================
elein(at)varlena(dot)com Varlena, LLC www.varlena.com

PostgreSQL Consulting, Support & Training

PostgreSQL General Bits http://www.varlena.com/GeneralBits/
=============================================================
I have always depended on the [QA] of strangers.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

----- End forwarded message -----

Browse pgsql-hackers by date

  From Date Subject
Next Message Scott Ribe 2003-12-04 02:24:53 Re: Transaction Question
Previous Message Stephan Szabo 2003-12-04 00:37:30 Re: Encoding problem with 7.4