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 3AA66D1B57C for ; Mon, 27 Oct 2003 15:40:16 +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 72255-08 for ; Mon, 27 Oct 2003 11:39:49 -0400 (AST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id E5C73D1B509 for ; Mon, 27 Oct 2003 11:39:43 -0400 (AST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Mon Oct 27 16:39:38 2003 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id QAA13615; Mon, 27 Oct 2003 16:39:37 +0100 (MET) From: Christoph Haller Message-Id: <200310271539.QAA10042@rodos> Subject: Re: extend INSERT by 'INSERT INTO table FETCH ... FROM cursor' syntax To: intrnl_edu@ilyichevsk.odessa.ua Date: Mon, 27 Oct 2003 16:39:36 MET Cc: pgsql-sql@postgresql.org In-Reply-To: <200310240000.00608.intrnl_edu@ilyichevsk.odessa.ua>; from "Alexander Vlasenko" at Oct 24, 103 7:52 pm X-Mailer: Elm [revision: 212.4] X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200310/341 X-Sequence-Number: 15741 > > Please CC me, I am not subscribed. > > An imaginary SQL statement > INSERT INTO table FETCH ... FROM cursor; > looks almost the same as currently available > INSERT INTO table SELECT ...; > > I tried it because I needed to insert a row in a table > after I DELETEd a set of rows, something like this: > > BEGIN; > DECLARE total CURSOR > FOR SELECT=20 > SUBSTR(datetime,1,7)||'-01 00:00:00' as month, > client, > SUM(money) > FROM stat > WHERE SUBSTR(datetime,1,7)=3D'2003-10' > GROUP BY month,client; > DELETE FROM stat WHERE SUBSTR(datetime,1,7)=3D'2003-10'; > INSERT INTO stat FETCH ALL FROM total; > COMMIT; > > but it does not work, chokes on FETCH ALL. > > I want to sum up all the money by month, delete all the rows > (possibly thousands of them) and insert one row per client > with monthly totals. > > Obviously I cannot swap order of INSERT and DELETE here. > > I hesitate to post this to pgsql-hackers@postgresql.org, > do I have to? ;) > > --=20 > Alexander Vlasenko > Using a temporary table to buffer the result comes to mind. Regards, Christoph