Re: question
От | A. Kretschmer |
---|---|
Тема | Re: question |
Дата | |
Msg-id | 20081008045946.GA12115@a-kretschmer.de обсуждение исходный текст |
Ответ на | Re: question (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | 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 по дате отправления: