create role in a pl/pgsql trigger - Mailing list pgsql-general

From Keresztury Balázs
Subject create role in a pl/pgsql trigger
Date
Msg-id 002601ca9eaa$5ba37b70$12ea7250$@hu
Whole thread Raw
Responses Re: create role in a pl/pgsql trigger  (Craig Ringer <craig@postnewspapers.com.au>)
List pgsql-general
hi,

I would like to write a trigger on a table which contains detailed
information about users. If I add a new user to this table, I'd like this
trigger to add the user to the database as well. Later I also want to
implement triggers for updating and deleting, but I got stuck at the first
part of this task.

Everything went fine until the point I had to insert the username into the
create role command. Appearently the command takes only parameters without
the ' signs, and the language supports only substituting parameters with the
apostrophe.

Any idea?

Thanks,
Balazs



Relevant metadata:

CREATE TABLE "felhasznalo"."felhasznalo" (
  "felhasznalo_id" VARCHAR NOT NULL,
  "vezeteknev" VARCHAR,
  "keresztnev" VARCHAR,
  "utolso_belepes" TIMESTAMP WITHOUT TIME ZONE DEFAULT now(),
  "kell_uj_jelszo" BOOLEAN DEFAULT false NOT NULL,
  "aktiv" BOOLEAN DEFAULT true NOT NULL,
  "aktiv_mettol" TIMESTAMP WITHOUT TIME ZONE DEFAULT now(),
  "aktiv_meddig" TIMESTAMP WITHOUT TIME ZONE,
  "modosito" VARCHAR DEFAULT "current_user"(),
  "modositas_idopont" TIMESTAMP WITHOUT TIME ZONE DEFAULT now(),
  CONSTRAINT "felhasznalo_pkey" PRIMARY KEY("felhasznalo_id")
) WITH OIDS;

CREATE TRIGGER "felhasznalo_letrehozas" BEFORE INSERT
ON "felhasznalo"."felhasznalo" FOR EACH ROW
EXECUTE PROCEDURE "public"."felhasznalo_letrehozas_trigger"();

CREATE OR REPLACE FUNCTION "public"."felhasznalo_letrehozas_trigger" (
)
RETURNS trigger AS
$body$
BEGIN
    CREATE ROLE NEW.felhasznalo_id INHERIT LOGIN IN ROLE "USR" ENCRYPTED
PASSWORD NEW.felhasznalo_id;
      RETURN NEW;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;




pgsql-general by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: pg dump.. issue with when using crontab
Next
From: Tom Lane
Date:
Subject: Re: pg dump.. issue with when using crontab