Search Postgresql Archives

Re: question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



am  Tue, dem 07.10.2008, um 21:20:53 -0400 mailte Tom Lane folgendes:
> Luis Castillo <luiscastillor@xxxxxxxxx> 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux