Can I use subselect as a function parameter?

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Can I use subselect as a function parameter?
Date: 2000-10-11 13:42:05
Message-ID: 200010111342.e9BDg5Y26824@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 Oliver(dot)Elphick(at)lfix(dot)co(dot)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 established my goings."
Psalms 40:1,2

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-10-11 14:25:55 Re: Can I use subselect as a function parameter?
Previous Message Thomas Lockhart 2000-10-11 05:51:59 Re: Re: [SQL] Q: spinlock on Alpha? (PG7.0.2)