SQLAlchemy calling function won't insert

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


SQLAlchemy calling function won't insert



so I am very confused about this weird behaviour I have with SQLAlchemy and PostgreSQL.



Let's say I have a table:


create table staging.my_table(
id integer DEFAULT nextval(bla bla bla..,
name text,
;



and a stored function:


create or replace function staging.test()
returns void
language plpgsql
as $function$
begin
insert into staging.my_table (name) values ('yay insert');
end;
$function$;



What I want to do now is call this function in python with sqlalchemy like this:


from sqlalchemy import create_engine

engine = create_engine('postgresql+psycopg2://foo:bar@localhost:5432/baz')
engine.execute('select staging.test()')



When I run this python code nothing get's inserted in my database. That's weird because when I replace the function call with select 1 and add .fetchall() to it it get's executed and I see the result in console when I print it.


select 1


.fetchall()



Let's say I run this code twice and nothing happens but code runs successful without errors.
If I switch to the database now and run select staging.test(); and select my_table I get: id: 3; name: yay insert.


select staging.test();


id: 3; name: yay insert



So that means the sequence is actually increasing when I run my python file but there is no data in my table.



What am I doing wrong? Am I missing something? I googled but didn't find anything.



Hope someone of you can find what I'm missing.



Best and thanks in advance :)









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Makefile test if variable is not empty