N
Neon2y ago
absent-sapphire

/sql endpoint transactions

Hi I was reading this post: https://discord.com/channels/1176467419317940276/1193786856215687238/1194217845056348200 Is there doco available for the /sql API endpoint? I'm trying to understand how to create a serializable transaction containing a SELECT and an INSERT where the latter depends on the result of the former. Is this possible with the /sql API? Thanks Ben
9 Replies
absent-sapphire
absent-sapphireOP2y ago
I guess I could do this with a INSERT...INTO...SELECT statement?
continuing-cyan
continuing-cyan2y ago
PostgreSQL Documentation
6.4. Returning Data from Modified Rows
6.4. Returning Data from Modified Rows # Sometimes it is useful to obtain data from modified rows while they are being …
continuing-cyan
continuing-cyan2y ago
Isnt this he what you need? Insert into xxxx returning…
absent-sapphire
absent-sapphireOP2y ago
Actually my transaction is a select -> insert -> update I think I need a CTE with RETURNING
continuing-cyan
continuing-cyan2y ago
update also supports the returning keyword do you need something like INSERT INTO ... SELECT FROM or is the select in order to get some other information for your insert?
absent-sapphire
absent-sapphireOP2y ago
Yeah thanks @Flo I think I can see a path forward now. Is there any update on the /sql API endpoint doco? Is there any way to control the transaction from the api client?
harsh-harlequin
harsh-harlequin2y ago
Hey @bensullivan, Can you share a sample query of what you're aiming at? I'm happy to debug and help.
absent-sapphire
absent-sapphireOP2y ago
I ended up going to vanilla JDBC for the transaction - it was too complicated with the API Thanks for offer of help
harsh-harlequin
harsh-harlequin2y ago
Alright, do let me know if you need anything!

Did you find this page helpful?