Re: rules question - Mailing list pgsql-general

From Richard Huxton
Subject Re: rules question
Date
Msg-id 200304301026.51897.dev@archonet.com
Whole thread Raw
In response to rules question  (ed despard <despareg@clarkson.edu>)
List pgsql-general
On Wednesday 30 Apr 2003 5:00 am, ed despard wrote:
> hi, i have a table named pursuit which has no data in it, currently to
> get data for the table i have a function that i call like: select *
> from pursuit_select_function(raceid), but i put in the raceid that im
> selecting for.  i would like to be able to treat this table like a view
> and make a query like select * from pursuit where raceid=9 or somthing
> and have a rule rewrite this into the function call. is there a way to
> have a rule that rewrites the query based on the qualifier of the query?

I think you're out of luck here.

For "where raceid=9" it's easy enough - just call "function(9)".
What if someone uses "where raceid in (7,8,9)" - does the planner write that
as "function(7) or function (8) or function(9)" and how does that interact
with your side-effects?

> the reason im not just using a normal view is that i have a sequence
> that needs to be reset before each select, so the
> pursuit_select_function resets the sequence and does the select query.

I was thinking you could create a rule with multiple queries for the action,
but unfortunately that's not supported for ON SELECT rules (according to my
docs). If it was, you could reset the sequence as the first query, then do
your processing for the second.

I take it you're using the sequence to number output rows?
--
  Richard Huxton


pgsql-general by date:

Previous
From: "Jim C. Nasby"
Date:
Subject: Re: Optimizer not using index on 120M row table
Next
From: David Goodenough
Date:
Subject: pg_dumpall -g problem