473,289 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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
0 4943

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Gilbert | last post by:
I'm quite stuck with this: I have an import table called ReferenceMatchingImport which contains data that has been sucked from a data submission. The contents of this table have to be imported...
2
by: yurps | last post by:
Hi I have a weird problem I want to cursor thru the values in a temporary table and use the values to do a select statement to insert into another temporary table...This select statement uses a...
25
by: Andreas Fromm | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Im building an user database with many tables keeping the data for the Address, Phone numbers, etc which are referenced by a table where I...
7
by: David Bear | last post by:
I have a dictionary that contains a row of data intended for a data base. The dictionary keys are the field names. The values are the values to be inserted. I am looking for a good pythonic...
8
by: carlospedr | last post by:
I have to insert data from about 30 tables into a single table (Users), to do so i used a cursor and a bit of dynamic sql, this should work fine if the tables have to do the select from had the...
8
by: gacuna | last post by:
i want to insert into a temporal table the result of a store procedure. on sql server the sentence would look like this (already working) INSERT INTO #SHIPINFO exec TESTDTA.S59RSH05 @SCBILLTO,...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
6
by: eighthman11 | last post by:
Hi everyone: Using Sql Server SQL 8 I'm trying to INSERT records into a "can software package" batch table. I have a work-table that mimics the batch table. After manipulating the records in...
0
by: gpspocket | last post by:
help me -CURSOR backward insert from End Date > to Start Date how to insert dates from end to start like this SELECT 111111,1,CONVERT(DATETIME, '17/03/2008', 103), CONVERT(DATETIME,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.