1

Can I do the following in PostgreSQL:

WHEN (my_session <> admin)
   CREATE OR REPLACE FUNCTION testing123 () RETURNS VOID AS
   ....



   ...
   //end of function here

In other words, if my_session <> admin is TRUE, the function will be created.

1 Answer 1

1

Use a DO statement for that, like this:

DO
$$DECLARE
   issuper boolean;
BEGIN
   /* check if current user is superuser */
   SELECT usesuper INTO issuper
      FROM pg_catalog.pg_user
      WHERE usename = CURRENT_USER;
   IF issuper THEN
      CREATE OR REPLACE FUNCTION testing123() RETURNS void AS ...;
   END IF;
END;$$;
Sign up to request clarification or add additional context in comments.

Comments

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.