Re: question - Mailing list pgsql-general

From A. Kretschmer
Subject Re: question
Date
Msg-id 20081008045946.GA12115@a-kretschmer.de
Whole thread Raw
In response to Re: question  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
am  Tue, dem 07.10.2008, um 21:20:53 -0400 mailte Tom Lane folgendes:
> Luis Castillo <luiscastillor@gmail.com> writes:
> > I would like to know how  can I control in my database the rows that a
> > user has inserted. I mean many users can insert information in a table
> > but when trying to update the information I want that a user can change
> > only those rows inserted by him. Is this possible with Postgresql?
>
> Sure, if you add a column that records which user inserted the row, and
> then make a BEFORE UPDATE trigger that throws an error if it doesn't
> match.

Additional, create a text-column with default current_user for the
inserts. Example:

kretschmer@pegasus:~$ psql -U kretschmer test
...

test=> create table usertab (id serial, username text default current_user);
NOTICE:  CREATE TABLE will create implicit sequence "usertab_id_seq" for serial column "usertab.id"
CREATE TABLE
test=*> insert into usertab values(default, default);
INSERT 0 1
test=*> select * from usertab;
 id |  username
----+------------
  1 | kretschmer
(1 row)



Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

pgsql-general by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: general table stats, ideas ?
Next
From: "Scott Marlowe"
Date:
Subject: Re: localhost (windows) performance