Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

using 'ALTER ROLE' in a function


  • From: Lutz Broedel <lb(at)fggm(dot)uni-hannover(dot)de>
  • To: pgsql-general(at)postgresql(dot)org
  • Subject: using 'ALTER ROLE' in a function
  • Date: Thu, 22 Mar 2007 14:40:33 +0100
  • Message-id: <46028751(dot)2080807(at)fggm(dot)uni-hannover(dot)de>

Dear list,

I'm trying to write a PL/pgSQL function that executes some code every time a user changes his/her password. The function is supposed to work like this:

CREATE OR REPLACE FUNCTION changePwd(varchar(255)) RETURNS boolean AS $$
DECLARE
	pwd varchar(255);
	curr_user name;
BEGIN
	curr_user = (SELECT session_user);
	pwd = $2;
	
	ALTER ROLE curr_user WITH ENCRYPTED PASSWORD pwd;
	-- [... do some other stuff ...]
	RETURN true;
END;
$$ LANGUAGE 'PLPGSQL';

but PostgreSQL returns:
ERROR:  Error »syntax error« at »$1« at character 13
QUERY:  ALTER ROLE  $1  WITH ENCRYPTED PASSWORD  $2

I have tried this in several ways and it seems, ALTER ROLE just does not accept a parameter instead of name. Does anybody have a solution for this?

Thanks in advance and best regards,
Lutz




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group