Reputation: 81
So I have a sybase stored procedure and I'm moving it in Postgres 9.5 but I can't seem to make a portion of it working. In the procedure there is an if clause that at the end has return 0 like below: In Sybase:
if @param = true begin
select col1, col2
from table
where <condition>
return 0
end
How can I use the return status in a Postgres function using plpgsql language?
Any help appreciated.
Upvotes: 1
Views: 940
Reputation: 45760
The PostgreSQL functions has not any similar to return status. Any function should to return data or should to raise a exception. The return status is not necessary. The programming in plpgsql is similar to Oracle's PL/SQL or IBM's DB2. Sybase, T-SQL is very far from PLpgSQL - good start is reading a manual, because lot of things are different - https://www.postgresql.org/docs/current/static/plpgsql.html
your code in PLpgSQL:
CREATE OR REPLACE FUNCTION foo(param boolean)
RETURNS SETOF tablename AS $$
BEGIN
IF param THEN
RETURN QUERY SELECT * FROM tablename
WHERE ..
ELSE
RAISE EXCEPTION 'xxxx';
END IF;
END;
$$ LANGUAGE plpgsql;
No exception - it is analogy return status 0, exception -- some nonzero return status.
Upvotes: 1