Advertisement
Joze

Untitled

Jan 16th, 2012
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Procedure de test_retrieve_items
  2. CREATE OR REPLACE FUNCTION get_all_test() RETURNS SETOF test_pepe AS 'select * from test_pepe;' language 'sql';
  3.  
  4. -- Procedure de test_add_item
  5.  
  6. CREATE OR REPLACE FUNCTION test_add_item (p_url IN VARCHAR, p_origin IN VARCHAR) RETURNS BOOLEAN
  7.     AS $BODY$
  8. BEGIN
  9.     INSERT INTO test_pepe (url,origin)
  10.         VALUES (p_url,p_origin);
  11.  
  12.     RETURN TRUE;
  13.    
  14. EXCEPTION
  15.     WHEN unique_violation THEN
  16.         RAISE unique_violation USING MESSAGE = 'TABLE test_pepe: DUPLICATED VALUE "' || p_url || '" ON FIELD NAMED "url"';
  17.  
  18.         RETURN FALSE;
  19.        
  20.     WHEN OTHERS THEN
  21.         RAISE EXCEPTION 'OTHER EXECP INSERTING VALUES (%, %)', p_url, p_origin USING HINT = 'Please check the values';
  22.         RETURN FALSE;
  23. END;
  24. $BODY$
  25.     LANGUAGE plpgsql;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement