-
Following example 11: https://sql.datapage.app/component.sql?component=form I've created a sql script that creates a temporary table, copies to it, and then merges from the temporary table to the permanent table. Typically, I use 'ON COMMIT DROP' when making temporary tables. On my second upload, sqlpage throws the error that my temporary table already exists. I kill the server, then put Finally, I add How should users work with sqlpage transactions? Is there a way to align transactions with request lifecycles? This pseudo code seems to work: COMMIT;
BEGIN;
CREATE TEMPORARY TABLE example_temp (
LIKE example
) ON COMMIT DROP;
COPY example_temp (my_id)
FROM
'example_form_input' (FORMAT 'csv', HEADER);
MERGE INTO example from example_temp;
SELECT
'redirect' AS component,
'/example' AS link;
COMMIT; Judiciously beginning and ending every sqlpage script with begin and commit negates the need for commit;begin; and commit; in some files. Not sure which is best. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello and thank you for the well-written report and reproduction. Currently, SQLPage does connection pooling, but does not do anything special at the end of an HTTP request, so it can put back a connection with an open transaction to the pool. I do agree that this behavior is not desirable. I opened issue #711 to track this. In the meantime, I think what you are currently doing ( |
Beta Was this translation helpful? Give feedback.
-
@lovasoa thanks for your continued support. Sqlpage is a real delight |
Beta Was this translation helpful? Give feedback.
Hello and thank you for the well-written report and reproduction.
Currently, SQLPage does connection pooling, but does not do anything special at the end of an HTTP request, so it can put back a connection with an open transaction to the pool.
I do agree that this behavior is not desirable. I opened issue #711 to track this.
In the meantime, I think what you are currently doing (
commit; begin;
at the beginning thencommit
at the end) is the best solution.