Skip site navigation (1) Skip section navigation (2)

RE: [SQL] RULE questions.

From: "Neil Burrows" <maillist(at)remo(dot)demon(dot)co(dot)uk>
To: "Jan Wieck" <jwieck(at)debis(dot)com>, "Neil Burrows" <maillist(at)remo(dot)demon(dot)co(dot)uk>
Cc: <pgsql-sql(at)postgreSQL(dot)org>
Subject: RE: [SQL] RULE questions.
Date: 1999-02-11 12:34:12
Message-ID: 000d01be55ba$d43b32c0$ (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-sql

> > I have what I first thought would be a trivial problem, in that
> I require
> > the 2 VARCHAR columns in the following table to have the data stored in
> > upper case.

>     1.  Make sure user_id is unique or extend the WHERE clause in
>         the UPDATE rule.  To explain why:

This is actually just a small test table, and the real one has quite a few
more columns, but I did mean to make user_id unique, just forgot.  :)

>     2.  Change  the  WHERE  clause  in the UPDATE rule to compare
>         against old.user_id and add "user_id  =  new.user_id"  to
>         the  SET  clause.  Otherwise  it would not be possible to
>         change the user_id because this thrown away by the  rule.

The thinking behind it was that user_id shouldn't be able changed but I
accidentally neglected to mention that.

> > 2) Users can still enter data straight into test_table in lower case
> > bypassing the "rules"

>     Not  necessarily.  Since  v6.4  rule  actions (in contrast to
>     triggers up to now) inherit the  access  permissions  of  the
>     owner of the relation they're fired on.

Ahh, I see.  I thought that the rule actions used the current users access
permissions, not the owners.  That's much handier, thanks.

>     In  addition to that, consider the case you really don't want
>     once given user_id's ever to change. Nor you like them to  be
>     ever reused. But they should disappear on DELETE.
>         CREATE TABLE test_table (user_id int,
>                                  name varchar(10),
>                                  pass varchar(10),
>                                  alive bool);

And that's a great way of doing what I was going to start looking at next.

>     The  Postgres rewrite rule system is the most powerful way to
>     do that.

Thanks very much for your time and comments here.  It's certainly made
things clearer.

Thanks again,

---[  Neil Burrows  ]-----------------------------------------------------
E-mail: neil(dot)burrows(at)gssec(dot)bt(dot)co(dot)uk             British Telecom Plc.
      : neil(at)pawprint(dot)co(dot)uk                     Glasgow Engineering Centre
Web   :            Highburgh Rd.  Glasgow  UK
-----------< Any views expressed are not those of my employer >-----------

In response to

pgsql-hackers by date

Next:From: D'Arcy J.M. CainDate: 1999-02-11 12:44:33
Subject: PQsocket
Previous:From: D'Arcy J.M. CainDate: 1999-02-11 12:33:00
Subject: Re: [SQL] RULE questions.

pgsql-sql by date

Next:From: pierreDate: 1999-02-11 14:42:46
Subject: [SQL] Rule problem (fwd)
Previous:From: D'Arcy J.M. CainDate: 1999-02-11 12:33:00
Subject: Re: [SQL] RULE questions.

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group