pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: ed despard <despareg@clarkson.edu>
To: pgsql-general@postgresql.org
Subject: Re: rules question
Date: Wed, 30 Apr 2003 10:26:51 +0100
Message-ID: <200304301026.51897.dev@archonet.com> (raw)
In-Reply-To: <55369696-7AC0-11D7-B730-0003938ABE54@clarkson.edu>
References: <55369696-7AC0-11D7-B730-0003938ABE54@clarkson.edu>

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




view thread (3+ messages)

Message-ID: <200304301026.51897.dev@archonet.com>
Permalink:  ../200304301026.51897.dev@archonet.com/
Also on:    postgresql.org/message-id/200304301026.51897.dev@archonet.com

 · 

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: dev@archonet.com, despareg@clarkson.edu, pgsql-general@postgresql.org
  Subject: Re: rules question
  In-Reply-To: <200304301026.51897.dev@archonet.com>

* 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