Passing input to a view?

From: Paul Lambert <paul(dot)lambert(at)autoledgers(dot)com(dot)au>
To: pgsql-sql(at)postgresql(dot)org
Subject: Passing input to a view?
Date: 2007-05-10 06:03:53
Message-ID: 4642B5C9.5000505@autoledgers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message A. Kretschmer 2007-05-10 06:14:27 Re: Passing input to a view?
Previous Message Robert Edwards 2007-05-09 23:49:32 Re: query to select a linked list