X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6C606D1B4E8 for ; Mon, 27 Oct 2003 18:38:53 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 97147-10 for ; Mon, 27 Oct 2003 14:38:22 -0400 (AST) Received: from davinci.ethosmedia.com (unknown [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 86BB5D1B4E1 for ; Mon, 27 Oct 2003 14:38:21 -0400 (AST) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3830410; Mon, 27 Oct 2003 10:39:01 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Christoph Haller , intrnl_edu@ilyichevsk.odessa.ua Subject: Re: extend INSERT by 'INSERT INTO table FETCH ... FROM cursor' syntax Date: Mon, 27 Oct 2003 11:35:58 -0800 User-Agent: KMail/1.4.3 Cc: pgsql-sql@postgresql.org References: <200310271539.QAA10042@rodos> In-Reply-To: <200310271539.QAA10042@rodos> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200310271135.59460.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/347 X-Sequence-Number: 15747 Alexander, > > BEGIN; > > DECLARE total CURSOR > > FOR SELECT=3D20 > > SUBSTR(datetime,1,7)||'-01 00:00:00' as month, > > client, > > SUM(money) > > FROM stat > > WHERE SUBSTR(datetime,1,7)=3D3D'2003-10' > > GROUP BY month,client; > > DELETE FROM stat WHERE SUBSTR(datetime,1,7)=3D3D'2003-10'; > > INSERT INTO stat FETCH ALL FROM total; > > COMMIT; > >=20 > > but it does not work, chokes on FETCH ALL. Well, there's two problems with your program: 1) INSERT INTO .... FETCH ALL is not currently implemented. You would need= to=20 use a loop, and insert one row at a time by value. 2) You can't insert the rows you've just deleted from the base tables. In= =20 your example, the TOTAL cursor would be empty. I think that what you real= ly=20 want is a temp table. --=20 -Josh Berkus Aglio Database Solutions San Francisco