Python Forum

Full Version: This result object does not return rows. It has been closed automatically
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi colleagues, Can you help me with this? I know that here are the most of discussion about this problem, but i can not solve it. I red that i have to use SET NOCOUNT ON; but it does not work
this is my script , which works in sql, but when i run his in python i get "This result object does not return rows. It has been closed automatically "

This script is saved aj sql1.sql , i use it in this
from sqlalchemy import create_engine
engine = create_engine()
f = open("sql1.sql", 'r')
df = pd.read_sql(f.read(),engine)
This is not python but SQL , it is sql1.sql
--update num2

declare
v_temp_date Date := '01.01.1900';

begin
for c in (
select t.r1, t.date1, t.num1, t.num3
from table t

order by t.r1, t.num1
)
loop
  if c.num1 = 1 or c.date1 >= v_temp_date then
    update table x set x.num2 = 0
    where x.num3 = c.num3;
    --v_go := True;
    v_temp_date := c.date1 + 90;
 elsif c.date1 < v_temp_date then
   update table  x set x.num2 = 1
   where x.num3 = c.num3;
 end if;
 commit;
 
  end loop;
  end;
Output:
ResourceClosedError: This result object does not return rows. It has been closed automatically.
Please post all the code.
(Jan-10-2024, 06:35 PM)deanhystad Wrote: [ -> ]Please post all the code.

I updated the code
(Jan-10-2024, 08:39 PM)deanhystad Wrote: [ -> ]Go read this:

https://www.geeksforgeeks.org/connecting...qlalchemy/
I red it , but problem is not how connect pandas with SQL , I know it , But when I use this script SQL (sql1.sql) it does not work and i get.
"This result object does not return rows. It has been closed automatically". I do not know where is mistake in the script SQL, because when i Run this script in SQL it works, But When i Run in Python it does not work.
I think the problem is exactly how to connect pandas to the database. I don't see how your code can possibly work, even if you ditch the script and try a simple query I don't see how your code can work.
Sorry, I can't see any problem. Sad