Search Postgresql Archives

Capturing return value of a function

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

 



Hi,

I have a function like this


CREATE OR REPLACE FUNCTION sp_insert(text, text, text, text)
  RETURNS text AS
$BODY$
    BEGIN
        INSERT INTO tbl(a,b,c,d)
        VALUES ($1,$2, $3, $4);

        RETURN 'success';
    END;
       
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

I was wondering what would the function return if insert fails.
I want it to return 'success'  upon a successful insert and 'failure' if insert fails.

Would the following implementation work for that?


CREATE OR REPLACE FUNCTION sp_insert(text, text, text, text)
  RETURNS text AS
$BODY$
    BEGIN
                    BEGIN
                            INSERT INTO tbl(a,b,c,d)
                            VALUES ($1,$2, $3, $4);
                            
                                    RETURN 'success';
                    END;

                      RETURN 'failure';
    END;
       
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

[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