467,073 Members | 1,336 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,073 developers. It's quick & easy.

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

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 pg***********@postgresql.org,
do I have to? ;)

--
Alexander Vlasenko

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #1
  • viewed: 4723
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by yurps | last post: by
7 posts views Thread by David Bear | last post: by
8 posts views Thread by carlospedr@gmail.com | last post: by
8 posts views Thread by nano2k | last post: by
6 posts views Thread by eighthman11 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.