1

The application "foo" uses this plpythonu source code to read the custom variable foo.transaction_id.

I guess this is way too complicated.

How to shorten/simplify below lines?

txid_list = list(plpy.execute(
    '''SELECT current_setting FROM current_setting('foo.transaction_id')'''))
txid_str = txid_list [0]['current_setting']
txid = int(txid_str)
3
  • 1
    select current_setting('foo.transaction_id') would just be the same, but I doubt there is a big difference in performance. Not sure if it's possible in Python do do something like txid := current_setting('foo.transaction_id') (as in PL/pgSQL)
    – user1822
    Jan 26, 2018 at 11:21
  • I think this is the idiomatic way if you really have to use PL/Python. Jan 26, 2018 at 13:28
  • @dezso above code is just one snippet of a bigger PL/Python method. I just thought to myself that this looks simplifiable.
    – guettli
    Jan 26, 2018 at 15:38

1 Answer 1

2
+25

Based on the documentation, you won't be able to simplify this. plpy offers a quite limited set of DB access functions, so you have to do everything using those - basically the way you do it already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.