1

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.

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the explanation. I was thinking of RAISE EXCEPTION but was not sure. It works for what I have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.