pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Wehr <paul@industrialsoftworks.com>
To: Keith Wong <keith@e-magine.com.au>
Cc: Nelson <nbrito@cmet.net>
Cc: Jie Liang <jliang@ipinc.com>
Cc: pgsql-general@hub.org <pgsql-general@hub.org>
Cc: pgsql-novice@hub.org <pgsql-novice@hub.org>
Cc: pgsql-sql@hub.org <pgsql-sql@hub.org>
Subject: Re: [SQL] how to store a query, that results in a table
Date: Sat, 23 Sep 2000 10:08:35 -0400
Message-ID: <39CCB963.2C038BBE@industrialsoftworks.com> (raw)
References: <39CB65A0.9DEF7ABB@cmet.net>
	<39CBD205.9A922DDE@ipinc.com>
	<4.3.2.7.0.20000923111232.00b65758@mail.e-magine.com.au>

Summary:  Proposed solution, and question on efficiency of technique

I don't know if this is what you are looking for, but I have a database where
I needed a relatively complex view (which I can do thanks to the expanded view
buffer in 7.0!, it didn't fit in 6.5.3), but I need to pass an "effective
date" to the view that needed to be in a range (so I couldn't just use a
column in one of the source tables) to get the results I want.  My "solution"
was to come up with an "effective dates" table with one column (primary keyed)
that I can put the dates in.  For example:

create table effective_date (date date, primary key (date) );

create view complex_view as select blah, ..... , effective_date.date
from tablea, tableb, tablec, effective_date
where tablea.foo=tableb.foo
   ....
  and effective_date.date between tablec.start_date=tablec.end_date
;

then, when I want to select rows from the view, I have to INSERT the date I
want into the "effective_date" table (which is effectively my "parameter"),
then I can select it from the view.  i.e.:

insert into effective_date values ('09/23/2000');  -- may "fail" if date is
already in the table, but if it is, who cares?

select *
from complex_view
where date='09/23/2000';

Now it would certainly be nicer if I could set some kind of global system
variable to the date, then reference that system variable in the view, but I
couldn't figure out any way to do it.  If anyone in the know is screaming out
loud at this technique, please point me in the right direction, I would love
to be able to skip the "Insert into effective_date..." step.

-paul



Keith Wong wrote:

> This is not really possible with postgresql at the moment.
> Better off trying to work around, perhaps using a view. That way you have a
> way to change the select
> statement without actually modifying your client code.
>
> Keith.
>
> At 06:09 PM 22/09/2000 -0400, Nelson wrote:
> >thank you jie Liang for your response, but my problems are:
> >1. How to store a query in the database.
> >2. How to give a parameter from outside of database, for example:
> >select * from table1 where row1 = my_parameter_outside.
> >Give me an example please.
> >
> >




view thread (7+ messages)  latest in thread

Message-ID: <39CCB963.2C038BBE@industrialsoftworks.com>
Permalink:  ../39CCB963.2C038BBE@industrialsoftworks.com/
Also on:    postgresql.org/message-id/39CCB963.2C038BBE@industrialsoftworks.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: paul@industrialsoftworks.com, keith@e-magine.com.au, nbrito@cmet.net, jliang@ipinc.com, pgsql-general@hub.org, pgsql-novice@hub.org, pgsql-sql@hub.org
  Subject: Re: [SQL] how to store a query, that results in a table
  In-Reply-To: <39CCB963.2C038BBE@industrialsoftworks.com>
  References: <39CB65A0.9DEF7ABB@cmet.net> <39CBD205.9A922DDE@ipinc.com> <4.3.2.7.0.20000923111232.00b65758@mail.e-magine.com.au> <39CCB963.2C038BBE@industrialsoftworks.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