910 questions
0
votes
1
answer
95
views
Creating an array of all indexedDB key values - function returns before completion [duplicate]
I am having a challenge with indexedDB keys not matching the record numbers. To correct this I need to cycle through the records and reset the ID to match the index. I am trying to form an array that ...
2
votes
1
answer
62
views
Do explicit locks in postgresql CTEs lock every row even with a cursor?
Let's say I have a table
CREATE TABLE mytable (
user_id bigint,
someval text
)
In my application, I want to lock and fetch every row for some given user_id e.g. 123 to do some additional ...
3
votes
1
answer
117
views
Update where current of cursor in a PL/pgSQL procedure. ERROR: cursor does not exist
I'm using 17.0.6 version (and 13 yet, in another test) of ODBC driver against a PostGreSQL 17 database, I got an unexplicable error when, from a PowerBuilder 12 application using the ODBC, I call a ...
1
vote
1
answer
111
views
Pandas dataframe insert to SQL Server using pyodbc fails if more than 1 record is present in batch
I have a large dataframe which I need to upload to SQL server. Due to volume of data, my code does the insert in batches. But, I am facing insert failure if the batch has more than 1 record in it. The ...
1
vote
1
answer
56
views
DB2 LUW How to CHECK/REORG Tables in a loop?
I have the following statements intended to CHECK/REORG tables in a loop. Partially, this works.
BEGIN
DECLARE SQLSTATE CHAR(5);
DECLARE RetState CHAR(5);
DECLARE SqlStmt ...
2
votes
1
answer
56
views
DB2 LUW Why does use of a cursor predicate generate an error?
I confirmed the following syntax in the DB2 LUW v11.5 manual (we are running DB2 LUW v11.5.9). And apparently this syntax has been supported at least since v9.7! This is in a stored procedure and, ...
1
vote
1
answer
79
views
How to add order clause in sequelize-cursor-pagination
I'm using the sequelize-cursor-pagination package to implement pagination in my Node-Postgres application. I need to order my results based on a field from an included (associated) model, but the ...
2
votes
0
answers
95
views
Cursor in MySQL procedure displaying errors [closed]
Declaring of cursors where data is through JSON format, I keep getting:
Column is not valid at this position, expecting for, lock, select, table, values, with …
-- Procedure to insert Project ...
0
votes
1
answer
41
views
How to debug PL/SQL procedure performance issues in OceanBase
Environment
OceanBase community edition 4.2.1 (MySQL Mode)
Table transactions has 1M+ rows, partitioned by id.
I'm encountering performance issues with a stored procedure in OceanBase. The procedure ...
0
votes
1
answer
134
views
SQL Server cursor inside cursor
I'm trying to use a cursor inside another cursor.
I'm facing a problem that's: I'm only be able of update one row of all the millions of rows, and the others are considered as 'not found' which is not ...
-2
votes
1
answer
46
views
Cursor to update 2 columns based on percentage increase on relevant data on same table
EmployeeName
Date
Salary1
Salary1_Percentage
Salary2
Salary2_Percentage
Alex A
2025-01-01
50
0 %
25
0 %
Alex A
2025-02-01
100
100 %
50
100 %
David C
2025-01-01
50
0 %
10
0 %
David C
2025-02-01
100
100 ...
-2
votes
1
answer
122
views
Using sp_executesql drop multiple tables
I’m trying to write a script to purge all the tables (and views and functions and procedures) from the current dbo schema in the current database.
Bolting together what I have learned from other ...
0
votes
0
answers
37
views
Is Primary Key required in Cursor [duplicate]
I searched extensively but I couldn't find clarity, whether Primary Key (In this case, composite of Foo1ID and Foo2ID) should be selected into foo_cursor, even if not used in procedure?
Is it ...
0
votes
1
answer
85
views
Nested SQL Server cursor has no records
I have a master detail schema with two tables. I am using a cursor within another cursor to loop them both.
BEGIN
--set NOCOUNT ON;
DECLARE Cur_Rule CURSOR LOCAL READ_ONLY FORWARD_ONLY FOR
...
0
votes
0
answers
49
views
Should sorting change the pagination key?
I am working with cursor pagination and sorting right now, for example you can paginate with cursor but you might also want it to be sorted in a certain field and direction for an API, i.e., api/?...
0
votes
1
answer
42
views
Azure SQL Server, Geographic Data and Scalar Variable Error
I have a dedicated Azure SQL environment where I am using a loop to get US States names like 'AB' or 'NY' etc and also geographical boundaries from the same table. Code and error below:
DECLARE ...
0
votes
1
answer
100
views
Mysql rowcount always returns 1 on INSERT IGNORE statement
I am using pymysql connector to do some inserts into my database. I am trying to return whether or not a record was added or updated.
My code is
import pymysql
db = pymysql.connect(host='127.0.0.1',...
1
vote
1
answer
71
views
Unable to use FETCH OFFSET syntax with inner CURSOR query in Oracle SQL
When attempting to query a resultset with an offset and a limit with the OFFSET x ROWS FETCH y ROWS ONLY syntax outside of the inner cursor
DECLARE
l_hits SYS_REFCURSOR;
BEGIN
OPEN l_hits for
...
0
votes
2
answers
102
views
ORA-06502: PL/SQL: numeric or value error: character string buffer too small when running function in select * from table
I am running the following code to generate parallel files of a big table in a small amount of time, even thought I have to join all the files afterwards in the operating system.
My environment is a ...
0
votes
1
answer
103
views
Cursor pagination for query based full-text search
I need to implement cursor based pagination on an endpoint which accepts a search query. The problem is that since rows will be ranked based on a relevance score derived from a full-text search in ...
0
votes
2
answers
133
views
How to fetch from cursor over single column of composite type into a variable of that type in PL/pgSQL?
Given:
CREATE TYPE my_struct AS (
a int4,
b text,
c float4
);
DO $$
DECLARE
my_cursor refcursor;
my_value my_struct;
BEGIN
OPEN my_cursor FOR SELECT (1, 'a', 10.0)::my_struct;
...
-1
votes
1
answer
136
views
Arcpy seems to not carry out my SQL clause
In the following code I meant to select rows from a table of cities named fc where the COUNTY='Socorro County' and ORDERED BY NAME:
fc="cities_copy"
where_selection=""""...
0
votes
0
answers
60
views
Use a SQL Server to make a cursor to do a select command across multiple databases on multiple servers
I have a lot of databases on a bunch of servers that all have an identical schema.
I current have been just building a string into $command (using STUFF) that is
select * from [server1].[DBname1].dbo.[...
0
votes
0
answers
155
views
Speeding up Snowflake Cursors for Parsing Transactional Table into Summary Rows
I have tag data that comes in individual rows with 3 types of events: Created, Modified and Deleted.
Tag data has the action date as well as the tag_name and if there is a tag_value. Modified events ...
1
vote
2
answers
176
views
Python not automatically closing a connection to sqlite3 after exiting WITH statement?
Here's a piece of code running on Python 3.10.5 -
with sqlite3.connect("test.db") as db:
cursor = db.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS testtable(id ...
2
votes
1
answer
111
views
Avoid using a cursor when creating new records in a table and update another with the newly generated keys?
Background
I recently had to fix a bug in an old WCF/Angular project. It is a To Do app that allows you to create tasks (A 'List' record) and mark it completed in 'ToDo' with some time calculations ...
0
votes
0
answers
338
views
How to correctly stop cursor execution and deallocate/close after there is an error?
I have a SQL cursor using which I loop over records in a table.
I'm trying to do some error handling wherein the execution should stop, and cursor closed/deallocated.
Based on my testing, if I do ...
0
votes
0
answers
59
views
Mongoose cursor times out after a couple of hours even though noCursorTimeout flag is set
export const cacheRecommendations = async () => {
const userCursor = UserModel.find({})
.cursor()
.addCursorFlag("noCursorTimeout", true);
let counter = 0;
...
0
votes
3
answers
1k
views
How can I do cursor pagination with string based columns and integer values?
I have a table, Customers, that has seven columns: ID, CustomerName, Address1, Address2, City, State, PostCode. I am trying to do cursor pagination via an API over the result set but the user can ...
2
votes
2
answers
116
views
How to get rid of CURSOR if every FETCH needs a SELECT based on previous result
We have a couple of tables, let's call them Sections and SectionTimeWindows. Sections table contains data about sections of 'movement', which starts at a place, ends at a place and has a type. The ...
2
votes
2
answers
84
views
SQL Query to group data without using cursor
I have the following table:
Category
Product
Date
Price
C1
P1
01/01/2024
1
C1
P2
01/01/2024
2
C1
P3
01/01/2024
3
C1
P1
01/02/2024
4
C1
P2
01/02/2024
5
C1
P3
01/02/2024
6
C1
P1
01/03/2024
7
C1
P2
01/03/...
0
votes
1
answer
541
views
Are PostgreSQL's cursors per connection or something else?
I'm using node-postgres (pg) and its pg-cursor extension. I noticed when reusing the same connection between multiple cursors, it locks due to what I would assume that a single connection is only able ...
0
votes
2
answers
2k
views
Dynamic SQL and cursor iteration in Snowflake
I've been sitting all weekend, trying to figure out the implementation of cursor iterations in Snowflake procedure blocks.
The goal is to create a dynamic procedure that when called checks all ...
1
vote
1
answer
141
views
Fetching data from cursor from Postgres stored procedure via ODBC in C
Thank you for your help in advance. I've got a simple SP in Postgres:
CREATE OR REPLACE PROCEDURE TEST_SP(INOUT _result_one refcursor = 'rs_resultone')
LANGUAGE plpgsql
AS $$
BEGIN
open _result_one ...
0
votes
2
answers
119
views
Looking for a way to avoid a cursor
I am trying to create a report that, among other things, lists how many new patients were seen in a particular month. A "new" patient is someone who has either 1) never been seen before, or ...
1
vote
0
answers
68
views
dbms_sql cursor_name as a parameter error
CREATE OR REPLACE FUNCTION fpp2(cur IN INTEGER) RETURN INTEGER
IS
rows_processed INTEGER;
BEGIN
dbms_output.PUT_LINE('cursor_fp2:' || cur);
rows_processed := DBMS_SQL.EXECUTE(cur);
...
1
vote
1
answer
155
views
Cursor object is not found in Visual FoxPro
I have a database containing a table called client that has, among others, column names like id, first, last,...
It is projected to extract each record and from it, assemble a PDF file named after ...
0
votes
1
answer
46
views
MySQL stored procedure error with two cursors in the same routine "ER_SP_CURSOR_NOT_OPEN: Cursor is not open"
In this stored procedure for an inventory system I want to process a packaging order for a product in kg according to the type of container and its capacity in kg.
This finally stores the existence of ...
0
votes
1
answer
254
views
Error occurred during update: ORA-01403: no data found when using update in forall in stored procedure in Oracle
Below is the stored procedure I have created. It is the "Create" stored procedure. I am getting error while updating the data.
SET SERVEROUTPUT ON;
CREATE OR REPLACE PROCEDURE ...
0
votes
1
answer
79
views
Declaring 2 Cursors in a Stored Procedure | SQL Error [1338] [42000]: Cursor declaration after handler declaration
I'm trying to declare two Cursors in a stored procedure but it shows
SQL Error [1338] [42000]: Cursor declaration after handler declaration
Cursor declaration after handler declaration
Cursor ...
0
votes
1
answer
95
views
SingleStore Procedure RowLock Issue
I have the SINGLESTORE stored procedure shown here which is going into rowlocks while inserting 8 million rows. Inserting 60k-80k, it runs fine.
The error that I am receiving is below. I am not sure, ...
-1
votes
1
answer
516
views
How to enter cursor as an input in procedure oracle [duplicate]
I want to create a procedure that uses cursor as an input in Oracle. I tried something like this:
cursor cur is select * from table t1;
and then also:
create or replace procedure (I want to input ...
0
votes
1
answer
168
views
Error when calling cursor.execute with psycopg2 sql.SQL object
I am trying to execute a raw update query using psycopg2 in django. The code is as below:
from django.db import connection
from psycopg2 import sql
model_instances_to_update = []
for model_instance ...
0
votes
0
answers
74
views
I need help solving the following error: 'CursorNotFound'
Here’s a shorter message to ask for help on Stack Overflow:
Hi everyone,
I need help with the following function:
def add_collection_content_vector_field(collection_name: str):
'''
Add a new ...
1
vote
1
answer
63
views
Empty tables specified from a list of table names without using a cursor
I have temporary data that is being uploaded from an external source into empty SQL Server tables. But not always the same tables. I need these tables to be cleared after a MERGE procedure is run.
The ...
0
votes
2
answers
140
views
Stack multiple columns in one - SQL
I have a table and the columns are 'Name' 'Product' 'Type' 'Date' 'Type1' 'Date1' 'Type2' 'Date2'..... (till type23 date23)
I want to stack Type1, Type2 under Type column and similarly Date1, Date2 ...
-1
votes
1
answer
25
views
Will select query get executed if it written in SP or Package declaration?
Create or Replace package SamplePackage
As
Cursor cur is select * from abc;
refCurParam as ref cursor return cur%rowtype;
Begin
End SamplePackage;
The above package used in SP in order to define type ...
0
votes
1
answer
86
views
table function macro called within a cursor
I have created a table function with SQL Macro.
When I want to use this within a procedure and cursor, it will not work.
CREATE OR REPLACE TYPE VARCHAR2_TYPE IS OBJECT (p VARCHAR2(4000));
...
0
votes
1
answer
63
views
SQL Cursor multiply two sets of lines
I am using Hana data studio (SQL) and need to write a cursor that takes the original dataset, makes column age set to 0 and sets the the fiscal quarter to the iterated value over a distinct list of ...
-1
votes
1
answer
150
views
SQL Server Cursor performance issue
I need help with optimizing a cursor or changing the code completely.
I have the below requirement:
Create column Sequence grouped by ColumnA, ColumnD and GroupA. StartA is used for sorting. Have ...