I am trying to create a PL/pgSQL function in PostgreSQL 9.3.6, but there is weird behavior when using the passed argument inside function body. Here is the 'very simple' function:
CREATE OR REPLACE FUNCTION myschema.test (myarg text) RETURNS text AS $$
DECLARE
entity text;
buffer text;
BEGIN
CREATE ROLE myarg;
RETURN myarg;
END;
$$ LANGUAGE plpgsql;
So, if for instance myarg
equals 'test':
- A role named 'myarg' is created (WRONG)
- 'test' is returned (CORRECT)
I searched for hours why this could be and no clue... security parameter? Why is myarg
not interpreted for creating roles?
Testing with phpPgAdmin through sql files if this has any impact.