pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Vlasenko <intrnl_edu@ilyichevsk.odessa.ua>
To: pgsql-general@postgresql.org
Subject: extend INSERT by 'INSERT INTO table FETCH ... FROM cursor' syntax
Date: Fri, 24 Oct 2003 00:00:00 +0300
Message-ID: <200310240000.00608.intrnl_edu@ilyichevsk.odessa.ua> (raw)

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 
  SUBSTR(datetime,1,7)||'-01 00:00:00' as month,
  client,
  SUM(money)
 FROM stat
 WHERE SUBSTR(datetime,1,7)='2003-10'
 GROUP BY month,client;
DELETE FROM stat WHERE SUBSTR(datetime,1,7)='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? ;)

-- 
Alexander Vlasenko



view thread (4+ messages)  latest in thread

Message-ID: <200310240000.00608.intrnl_edu@ilyichevsk.odessa.ua>
Permalink:  ../200310240000.00608.intrnl_edu@ilyichevsk.odessa.ua/
Also on:    postgresql.org/message-id/200310240000.00608.intrnl_edu@ilyichevsk.odessa.ua

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: intrnl_edu@ilyichevsk.odessa.ua, pgsql-general@postgresql.org
  Subject: Re: extend INSERT by 'INSERT INTO table FETCH ... FROM cursor' syntax
  In-Reply-To: <200310240000.00608.intrnl_edu@ilyichevsk.odessa.ua>
  References: <200310240000.00608.intrnl_edu@ilyichevsk.odessa.ua>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox