X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C2B75563AA for ; Tue, 15 Mar 2005 09:33:35 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68102-02 for ; Tue, 15 Mar 2005 09:33:34 +0000 (GMT) Received: from ns.aprote.ee (ns.aprote.ee [80.235.78.106]) by svr1.postgresql.org (Postfix) with ESMTP id 5A10C54EE6 for ; Tue, 15 Mar 2005 09:33:32 +0000 (GMT) Received: Message by Barricade ns.aprote.ee with ESMTP id j2F9YKm2004269 for ; Tue, 15 Mar 2005 11:34:21 +0200 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0 Subject: Re: Parameterized views proposition Date: Tue, 15 Mar 2005 11:33:33 +0200 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Parameterized views proposition Thread-Index: AcUnUexNULfSyXwVQHCGdXdz6D7KMwB6+soA From: "Tambet Matiisen" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/213 X-Sequence-Number: 20692 ... >=20 > I wonder if it could be possible to improve CREATE VIEW=20 > syntax by adding parameters? Something like this: >=20 > 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 =3D s.product_id and s.date=20 > between $1 and $2 group by p.product_id >=20 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.=20 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=20 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