pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron Peterson <rpeterso@mtholyoke.edu>
To: Rick Schumeyer <rschumeyer@ieee.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: simulating row ownership
Date: Tue, 11 Jan 2005 08:38:21 -0500
Message-ID: <20050111133821.GA27537@mtholyoke.edu> (raw)
In-Reply-To: <001901c4f4d9$395726f0$0200a8c0@dell8200>
References: <001901c4f4d9$395726f0$0200a8c0@dell8200>

On Fri, Jan 07, 2005 at 11:52:07AM -0500, Rick Schumeyer wrote:

> I have a table where I want everyone to be able to be able to insert
> and select.

> But they should only be able to update and delete rows that they
> "own".  The table has a column indicating the owner.

> What is the best way to accomplish this?  I'm not real familiar with
> rules, but it seems that I can do this with rules for update and
> delete applied to the table.

Using rules, you could do something like the following:

CREATE TABLE test (
  aname TEXT PRIMARY KEY
);

INSERT INTO test ( aname ) VALUES ( 'aaa' );
INSERT INTO test ( aname ) VALUES ( 'yourusername' );

CREATE RULE lock_test_user_update
AS ON UPDATE TO test
WHERE old.aname = CURRENT_USER
DO INSTEAD nothing;

CREATE RULE lock_test_user_delete
AS ON DELETE TO test
WHERE old.aname = CURRENT_USER
DO INSTEAD nothing;

-- 
Ron Peterson
Network & Systems Manager
Mount Holyoke College
http://www.mtholyoke.edu/~rpeterso



view thread (4+ messages)  latest in thread

Message-ID: <20050111133821.GA27537@mtholyoke.edu>
Permalink:  ../20050111133821.GA27537@mtholyoke.edu/
Also on:    postgresql.org/message-id/20050111133821.GA27537@mtholyoke.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rpeterso@mtholyoke.edu, rschumeyer@ieee.org
  Subject: Re: simulating row ownership
  In-Reply-To: <20050111133821.GA27537@mtholyoke.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox