From: | Philippe Lang <philippe(dot)lang(at)attiksystem(dot)ch> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Sanity check on view |
Date: | 2010-08-05 09:30:52 |
Message-ID: | 8AE5A725DAF7364F97FF75D99E45B65759955958@SBS1.attiksystem.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I've got a view, which is supposed to be called with a WHERE clause, like:
------------------------------------------------------------
SELECT * FROM data_view WHERE od_id = '1234';
------------------------------------------------------------
I'd like to make sure it is called correctly: not all "od_id" values should be permitted.
I came up with this solution:
------------------------------------------------------------
-- FUNCTION: get_data_view
------------------------------------------------------------
CREATE OR REPLACE FUNCTION get_data_view(integer)
RETURNS SETOF data_view AS
'
DECLARE
data RECORD;
BEGIN
FOR data IN SELECT * FROM data_view WHERE od_id = $1 LOOP
IF data.foo != ''bar'' THEN
RAISE EXCEPTION ''blablabla'';
END IF;
RETURN NEXT data;
END LOOP;
RETURN;
END;
'
LANGUAGE 'plpgsql' VOLATILE;
------------------------------------------------------------
Is there maybe a better alternative?
I tried to raise an exception from sql directly, in a "case... when...", but it didn’t work...
Thanks!
-------------------------------------------------------------
Attik System web : http://www.attiksystem.ch
Philippe Lang phone: +41 26 422 13 75
rte de la Fonderie 2 gsm : +41 79 351 49 94
1700 Fribourg pgp : http://keyserver.pgp.com
From | Date | Subject | |
---|---|---|---|
Next Message | AI Rumman | 2010-08-05 12:23:54 | column depends on sequence |
Previous Message | =?EUC-KR?B?s+vH9ryu?= | 2010-08-05 08:52:44 | how can we resolving locking state.... |