I'm trying to insert values into a Postgres11 database with raw sqlalchemy text() queries.
The following SQL query works correctly when I run it through psql-client:
WITH a AS (
INSERT INTO person (id)
VALUES ('a')
RETURNING id
)
INSERT INTO person_info (person_id)
SELECT id
FROM a;
All rows are correctly inserted:
# select id from person;
id
----
a
(1 row)
However, if I create an engine in sqlalchemy and call execute on it with an identical query, it runs successfully but no rows are inserted:
>>> engine.execute("WITH a AS (INSERT INTO person (id) VALUES ('b') RETURNING id) INSERT INTO person_info (person_id) SELECT id from a")
<sqlalchemy.engine.result.ResultProxy object at 0x7f25e6c2a090>
But no new row was inserted:
# select id from person;
id
----
a
(1 row)
In what way is running the query through the psql-client different from executing it through sqlalchemy?