Replies: 5 comments
-
You should use PL/pgSQL. |
Beta Was this translation helpful? Give feedback.
-
Consider using the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the responses. In my specific case, I happen to be using CockroachDB, which does not seem to support PL/pgSQL for functions, just SQL. I have realized that for Multiple (Dependent) Inserts, Common Table Expressions using
@jtv : Any thoughts on transaction support for combining the 'BEGIN' and 'END' with the first-and-last statement? e.g. imagine if you want to run two SELECT statements in parallel, you could do:
which instead of doing 4 round trips with:
it would actually just do 2:
|
Beta Was this translation helpful? Give feedback.
-
About the combining of It does all get a bit messy and if anything fails, you'd probably be best off ditching the entire connection. I should say that |
Beta Was this translation helpful? Give feedback.
-
Sounds good - I can experiment with things on my side, and see if there is something useful to share later. Appreciate the input from everyone! |
Beta Was this translation helpful? Give feedback.
-
Hi,
In my use-case, the round-trip time to my database is a bit high, and while I'm separately working on moving my application closer to my database, I'm trying to reduce the number of round trips.
I have a few specific cases:
Transactions
I'm using
pqxx::transaction
, and have the style of:Two related questions:
BEGIN;
. I'm wondering if it could actually be done lazily, and pre-pended to the first statement (even optionally, a lazy-txn if you will).txn.exec_params1_and_commit (...)
, to reduce a RTT.While these don't seem too complicated to support to me, just curious if I'm missing it - or if my needs are different than others.
Multiple inserts.
Sometimes I have multiple dependent inserts, like:
INSERT INTO table_a (row_a) VALUES($1) RETURNING id;
INSERT INTO table_b (table_a_id) VALUES($1)
It seems unfortunate to have another round-trip just to use a dependent value. I realize this may be more of a "postgres would need to support this" - just confirming.
Thanks!
Kyle
Beta Was this translation helpful? Give feedback.
All reactions