pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Passing input to a view?
3+ messages / 3 participants
[nested] [flat]

* Passing input to a view?
@ 2007-05-10 06:03 Paul Lambert <paul.lambert@autoledgers.com.au>
  2007-05-10 06:14 ` Re: Passing input to a view? A. Kretschmer <andreas.kretschmer@schollglas.com>
  2007-05-10 06:14 ` Re: Passing input to a view? Phillip Smith <phillip.smith@weatherbeeta.com.au>
  0 siblings, 2 replies; 3+ messages in thread

From: Paul Lambert @ 2007-05-10 06:03 UTC (permalink / raw)
  To: pgsql-sql

Is it possible to define a view to use input parameters rather than a 
hard-wired value in a where clause?

I.e. I have the following view:

CREATE OR REPLACE VIEW invoiced_repairs AS
SELECT ro_header.ro_number, ro_header.received_date, vehicles.vehicle_id,
	vehicles.model, vehicles.engine, vehicles.transmission, 
ro_header.odometer_reading,
	ro_header.service_description,
	(
          CASE WHEN (vehicles.month_of_manufacture <> '' AND 
vehicles.year_of_manufacture <> '')
	 THEN
		(vehicles.month_of_manufacture || '/' || vehicles.year_of_manufacture)
	 ELSE
		''
          END
         ) AS date_of_manufacture,
	vehicles.identification_number, vehicles.engine_number from ro_header
INNER JOIN vehicles USING (vehicle_address)
WHERE ro_header.received_date between '1-jan-2007' AND '10-May-2007';
ALTER TABLE invoiced_repairs OWNER TO postgres;

Instead of having it set to 1-Jan-2007 and 10-May-2007 for the dates, 
can I specify that those values should be passed to the view? Or would I 
need to change this to an SQL language function?

I can't find anything in the documentation that answers this, but maybe 
I'm not looking hard enough.

Thanks in advance.

-- 
Paul Lambert
Database Administrator
AutoLedgers




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Passing input to a view?
  2007-05-10 06:03 Passing input to a view? Paul Lambert <paul.lambert@autoledgers.com.au>
@ 2007-05-10 06:14 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
  1 sibling, 0 replies; 3+ messages in thread

From: A. Kretschmer @ 2007-05-10 06:14 UTC (permalink / raw)
  To: pgsql-sql

am  Thu, dem 10.05.2007, um 14:03:53 +0800 mailte Paul Lambert folgendes:
> Is it possible to define a view to use input parameters rather than a 
> hard-wired value in a where clause?

As far as i know, no.


> Instead of having it set to 1-Jan-2007 and 10-May-2007 for the dates, 
> can I specify that those values should be passed to the view? Or would I 
> need to change this to an SQL language function?
> 
> I can't find anything in the documentation that answers this, but maybe 
> I'm not looking hard enough.

You can write a so called 'set returning function' instead.
Read more:
http://www.postgresql.org/docs/current/static/xfunc-sql.html#XFUNC-SQL-TABLE-FUNCTIONS


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Passing input to a view?
  2007-05-10 06:03 Passing input to a view? Paul Lambert <paul.lambert@autoledgers.com.au>
@ 2007-05-10 06:14 ` Phillip Smith <phillip.smith@weatherbeeta.com.au>
  1 sibling, 0 replies; 3+ messages in thread

From: Phillip Smith @ 2007-05-10 06:14 UTC (permalink / raw)
  To: pgsql-sql

Remove the WHERE clause that specifies the date so the view includes all
dates, then apply the WHERE clause when selecting the view.

SELECT	*
FROM		invoiced_repairs
WHERE		invoiced_repairs.received_date BETWEEN '1 Jan 2007' AND '10
May 2007';


-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of Paul Lambert
Sent: Thursday, 10 May 2007 16:04
To: pgsql-sql@postgresql.org
Subject: [SQL] Passing input to a view?

Is it possible to define a view to use input parameters rather than a 
hard-wired value in a where clause?

I.e. I have the following view:

CREATE OR REPLACE VIEW invoiced_repairs AS
SELECT ro_header.ro_number, ro_header.received_date, vehicles.vehicle_id,
	vehicles.model, vehicles.engine, vehicles.transmission, 
ro_header.odometer_reading,
	ro_header.service_description,
	(
          CASE WHEN (vehicles.month_of_manufacture <> '' AND 
vehicles.year_of_manufacture <> '')
	 THEN
		(vehicles.month_of_manufacture || '/' ||
vehicles.year_of_manufacture)
	 ELSE
		''
          END
         ) AS date_of_manufacture,
	vehicles.identification_number, vehicles.engine_number from
ro_header
INNER JOIN vehicles USING (vehicle_address)
WHERE ro_header.received_date between '1-jan-2007' AND '10-May-2007';
ALTER TABLE invoiced_repairs OWNER TO postgres;

Instead of having it set to 1-Jan-2007 and 10-May-2007 for the dates, 
can I specify that those values should be passed to the view? Or would I 
need to change this to an SQL language function?

I can't find anything in the documentation that answers this, but maybe 
I'm not looking hard enough.

Thanks in advance.

-- 
Paul Lambert
Database Administrator
AutoLedgers


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@postgresql.org so that your
       message can get through to the mailing list cleanly


*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2007-05-10 06:14 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-05-10 06:03 Passing input to a view? Paul Lambert <paul.lambert@autoledgers.com.au>
2007-05-10 06:14 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2007-05-10 06:14 ` Phillip Smith <phillip.smith@weatherbeeta.com.au>

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