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