2

Well, after insert a user in systemuser, i like to create a ROLE for PostgreSQL, using the password of new user. But when i try create the user, this error appears:

Blockquote ERROR: syntax error at or near "NEW" LINE 24: ALTER USER NEW.login ENCRYPTED PASSWORD NEW.password...

CREATE OR REPLACE FUNCTION trg_insertuser() 
RETURNS TRIGGER AS $trg_insertuser$
DECLARE
BEGIN
    IF (TG_OP = 'DELETE') THEN
        DROP USER OLD.login;
    ELSIF (TG_OP = 'UPDATE') THEN
        ALTER USER OLD.login ENCRYPTED PASSWORD NEW.password;
    ELSIF (TG_OP = 'INSERT') THEN       
        CREATE USER NEW.login ENCRYPTED PASSWORD NEW.password CREATEDB IN GROUP group_user;
    END IF;
    RETURN NULL;
END;
$trg_insertuser$ LANGUAGE plpgsql;

What's happend?

1 Answer 1

2

use execute.

execute 'drop user ' || quote_ident(OLD.login);

etc...

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.