Thread: Can I use subselect as a function parameter?

Can I use subselect as a function parameter?

From
"Oliver Elphick"
Date:
I want to do this:

CREATE FUNCTION ean_checkdigit(bpchar, bpchar) RETURNS BOOLEAN     AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE 'C';

CREATE TABLE product (  id                   CHAR(10)     PRIMARY KEY,  brand                CHAR(12)     REFERENCES
brandname(id)                                              ON UPDATE CASCADE
  ON DELETE NO ACTION,  eancode              CHAR(6)      CHECK (eancode IS NULL
OReancode ~ '[0-9]{6}'), ...,
 
  CONSTRAINT ean CHECK (      CASE WHEN eancode IS NULL OR brand IS NULL        THEN 't'        ELSE ean_checkdigit(
           (SELECT ean_prefix                    FROM brandname, product                    WHERE brandname.id =
product.brand               ), eancode)      END  )
 
);

The parser accepts it, but when it is run on a line that matches the ELSE in the constraint, I get:

copy product from '/usr1/avoca/dumps/dbdump.product'
ERROR:  copy: line 2, ExecEvalExpr: unknown expression type 108


Can this be made to work at all (in 7.0.2)?

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
========================================   "I waited patiently for the LORD; and he inclined unto      me, and heard my
cry.He brought me up also out of an      horrible pit, out of the miry clay, and set my feet      upon a rock, and
establishedmy goings."                                                      Psalms 40:1,2 
 




Re: Can I use subselect as a function parameter?

From
Philip Warner
Date:
At 14:42 11/10/00 +0100, Oliver Elphick wrote:
>
>   CONSTRAINT ean CHECK (
>       CASE WHEN eancode IS NULL OR brand IS NULL
>         THEN 't'
>         ELSE ean_checkdigit(
>                 (SELECT ean_prefix
>                     FROM brandname, product
>                     WHERE brandname.id = product.brand
>                 ), eancode)
>       END
>   )
>);
>
>
>Can this be made to work at all (in 7.0.2)?
>

The short answer is that subselect in CHECK is not currently supported, and
is not planned for 7.1.

There was a thread about subselect in CHECK not so long ago (see 'checking
number of entries' on or around the 29/9). There was apparently also an
earlier discussion in which the meaning were not deemed to be clear. I
think the most recent discussion at least resolved the meaning, but not the
locking issues.


----------------------------------------------------------------
Philip Warner                    |     __---_____
Albatross Consulting Pty. Ltd.   |----/       -  \
(A.B.N. 75 008 659 498)          |          /(@)   ______---_
Tel: (+61) 0500 83 82 81         |                 _________  \
Fax: (+61) 0500 83 82 82         |                 ___________ |
Http://www.rhyme.com.au          |                /           \|                                |    --________--
PGP key available upon request,  |  /
and from pgp5.ai.mit.edu:11371   |/


Re: Can I use subselect as a function parameter?

From
Tom Lane
Date:
Philip Warner <pjw@rhyme.com.au> writes:
> The short answer is that subselect in CHECK is not currently supported, and
> is not planned for 7.1.

We should, however, try to make 7.1 deliver a more helpful error message
;-).  I've put a note about it on my todo list.
        regards, tom lane