RE: Executing stored procs

From: Anthony Waye <anthony(dot)waye(at)arq(dot)group>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: RE: Executing stored procs
Date: 2020-01-16 01:01:30
Message-ID: SY2PR01MB2698CF26823EECB6643F097386360@SY2PR01MB2698.ausprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Ah awesome! Thanks Daniele that appears to have worked!

Thanks
Anthony Waye
Senior Systems Engineer - DevOps (Microsoft)
[cid:image001(dot)png(at)01D5CC52(dot)FFE32B00]
M 0400167098
D 0732307463
Level 3, 192 Ann Street, Brisbane, QLD 4000
arq.group<http://www.arq.group/>

[cid:image002(dot)png(at)01D5CC52(dot)FFE32B00]<https://www.linkedin.com/company/arqgroup/>
The information contained in this email message may be confidential. If you are not the intended recipient any use, distribution, disclosure or copying of this information is prohibited. If you receive this email in error, please tell us by return email and delete it and any attachments from your system.

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Sent: Wednesday, 15 January 2020 10:06 PM
To: Anthony Waye <anthony(dot)waye(at)arq(dot)group>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Executing stored procs

On Wed, Jan 15, 2020 at 7:37 AM Anthony Waye <anthony(dot)waye(at)arq(dot)group<mailto:anthony(dot)waye(at)arq(dot)group>> wrote:

Essentially results in a SQL query of: CALL "stg_customervip"."sp_stg_customer"(37::bigint, '2020-01-15 05:52:31'::timestamp)
If I take that query and run it directly in redshift it runs successfully but via psycopg2 it returns:

psycopg2.errors.FeatureNotSupported: TRUNCATE cannot be invoked from a procedure that is executing in an atomic context.
HINT: Try calling the procedure as a top-level call i.e. not from within an explicit transaction block. Or, if this procedure (or one of its ancestors in the call chain) was created with SET config options, recreate the procedure without them.
CONTEXT: SQL statement "TRUNCATE table stg_customervip.Customer"

While that error sounds legitimate I think it might be a redherring because it does execute successfully if I do it manually against redshift.

Probably if you run it manually you do it outside a transaction. Psycopg starts a transaction automatically (no, I don't think it's a good idea, but it's part of the specs)

http://initd.org/psycopg/docs/usage.html#transactions-control

Try setting `redshift_conn.autocommit = True` after connection creation, and do without the `commit()`s.

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniel Fortunov 2020-02-15 16:55:49 Re: Nested transactions support for code composability
Previous Message Daniele Varrazzo 2020-01-15 12:05:37 Re: Executing stored procs