Re: extend INSERT by 'INSERT INTO table FETCH ... FROM cursor' syntax

From: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>
To: intrnl_edu(at)ilyichevsk(dot)odessa(dot)ua
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: extend INSERT by 'INSERT INTO table FETCH ... FROM cursor' syntax
Date: 2003-10-27 16:39:36
Message-ID: 200310271539.QAA10042@rodos
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

>
> 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(at)postgresql(dot)org,
> do I have to? ;)
>
> --=20
> Alexander Vlasenko
>
Using a temporary table to buffer the result comes to mind.
Regards, Christoph

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-10-27 16:47:09 Re: Timestamp and interval precision
Previous Message Greg Stark 2003-10-27 16:36:10 Re: Recomended FS

Browse pgsql-sql by date

  From Date Subject
Next Message mohan 2003-10-27 17:10:31 URGENT!!! changing Column size
Previous Message Tom Lane 2003-10-27 16:05:34 Re: Query planner: current_* vs. explicit date