By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

Domains and function

P: n/a

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? 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"
================================================== ==========
el***@varlena.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

Nov 12 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.