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
                                         OR eancode ~ '[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                                [EMAIL PROTECTED]
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 established my goings."              
                                         Psalms 40:1,2 


Reply via email to