Re: Parameterized views proposition - Mailing list pgsql-sql

From Tambet Matiisen
Subject Re: Parameterized views proposition
Date
Msg-id A66A11DBF5525341AEF6B8DE39CDE770088054@black.aprote.com
Whole thread Raw
In response to Parameterized views proposition  ("Tambet Matiisen" <t.matiisen@aprote.ee>)
Responses Re: Parameterized views proposition  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
...
>
> I wonder if it could be possible to improve CREATE VIEW
> syntax by adding parameters? Something like this:
>
> CREATE VIEW product_sales(date,date) AS
> select p.product_id, coalesce(sum(s.amount), 0)
> from product p
> left join sales s on p.product_id = s.product_id and s.date
> between $1 and $2 group by p.product_id
>

I noticed that braces after view name are already reserved for renaming
view columns. OK, then this syntax won't do. Isn't there some suggestion
in SQL standards? Quick search with Google revealed only that FoxPro has
parameterized views, but the syntax is quite different.

I've heard people talking about parameterized views since I started
database programming. So, PostgreSQL could be the first to really
implement them :). How tough it would be to implement

CREATE VIEW xxx PARAMETERS (yyy) AS zzz;

as

CREATE TYPE xxx;
CREATE FUNCTION xxx(yyy) RETURNING SETOF xxx LANGUAGE sql AS 'zzz';

Would you suggest it as first step in hacking PostgreSQL sources?
 Tambet


pgsql-sql by date:

Previous
From: Christoph Haller
Date:
Subject: Re: How to cast VARCHAR to BYTEA and vice-versa?
Next
From: U K Laxmi
Date:
Subject: comparing 2 tables