Re: question

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: question
Date: 2008-10-08 04:59:46
Message-ID: 20081008045946.GA12115@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am Tue, dem 07.10.2008, um 21:20:53 -0400 mailte Tom Lane folgendes:
> Luis Castillo <luiscastillor(at)gmail(dot)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(at)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-10-08 07:33:01 Re: localhost (windows) performance
Previous Message Scott Marlowe 2008-10-08 03:02:42 Re: general table stats, ideas ?