Search Postgresql Archives

Sanity check on view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 


Attachment: PGP.sig
Description: PGP signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux