Re: Triggers and Domains

From: Lennin Caro <lennin(dot)caro(at)yahoo(dot)com>
To: pgsql-novice(at)postgresql(dot)org, ekekakos <ekekakos(at)hol(dot)gr>
Subject: Re: Triggers and Domains
Date: 2009-08-31 16:10:20
Message-ID: 702290.46500.qm@web59511.mail.ac4.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

--- On Sun, 8/30/09, ekekakos <ekekakos(at)hol(dot)gr> wrote:

From: ekekakos <ekekakos(at)hol(dot)gr>
Subject: Re: [NOVICE] Triggers and Domains
To: pgsql-novice(at)postgresql(dot)org
Date: Sunday, August 30, 2009, 6:25 PM

It does not work.
I run your script
create domain username as text default user;
through PGADMIN and I get the following
CREATE DOMAIN username
  AS text
  DEFAULT "current_user"();
ALTER DOMAIN username OWNER TO ekekakos;

I create a field in a table and I am getting the following script:
ALTER TABLE "Library"."Contacts" ADD COLUMN "LastUser" username;
ALTER TABLE "Library"."Contacts" ALTER COLUMN "LastUser" SET STORAGE
EXTENDED;

And it does not work during the update.

Thanks
Elias

Tom Lane-2 wrote:
>
> ekekakos <ekekakos(at)hol(dot)gr> writes:
>> Thanks but how, in SQL server you put the function USER() (if I remember
>> well) and it works.
>> Here it does not work.
>
> Define "does not work", please?
>
> regression=# create domain username as text default user; 
> CREATE DOMAIN
> regression=# create table foo(f1 int, lastupdateuser username);
> CREATE TABLE
> regression=# insert into foo(f1) values(42);
> INSERT 0 1
> regression=# select * from foo;
>  f1 | lastupdateuser
> ----+----------------
>  42 | postgres
> (1 row)
>
>
>             regards, tom lane
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>
>

you can use "select current_user" to get the current user and use in the update trigger

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tim Bowden 2009-09-01 03:29:48 Re: Problem starting pgsql server on Mac OS X. Pg_hba.conf reading permission.
Previous Message Dante torio 2009-08-31 15:11:39 postgis/ posgresql trigger