Accessing serials through rules

From: Rick Delaney <rick(at)consumercontact(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Accessing serials through rules
Date: 2001-03-19 22:10:45
Message-ID: 3AB683E5.39E9F719@consumercontact.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

With rules, I can allow people to insert into a table that they don't
otherwise have access to. And default values seem to get inserted fine
except when the field is type serial (and the default is from a
sequence). Then you get write permission errors on the associated
sequence. Should it be like this?

Example:

CREATE TABLE mine (
id serial,
pub integer,
priv integer
);
CREATE VIEW ours AS SELECT id, pub FROM mine;
CREATE RULE ours_ins AS ON INSERT TO ours DO INSTEAD
INSERT INTO mine (pub) VALUES (NEW.pub);
GRANT ALL ON ours TO public;

Now connect as someone else...

INSERT INTO ours (pub) VALUES (1);
ERROR: mine_id_seq.nextval: you don't have permissions to set sequence
mine_id_seq

I thought rules were supposed to just run as the owner of the table they
were defined on. If I grant permissions on the sequence directly, then
those users could mess with its values, couldn't they?

select version();
version
------------------------------------------------------------------------
PostgreSQL 7.1beta4 on i586-pc-linux-gnu, compiled by GCC egcs-2.91.66

--
Rick Delaney
rick(at)consumercontact(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2001-03-19 22:57:51 Re: concurrent updates problem
Previous Message Bruce Momjian 2001-03-19 22:06:49 Re: [GENERAL] case insensitive unique index (part 2)