Open phoe opened 5 years ago
Hm. Even if I split the above function into three subfunctions, I still think that transactions should work in this case - I can't see splitting this function into five just to satisfy the no-multiple-commands constraint.
-- name: set-initial-data @execute
-- Fills the database with the initial data.
BEGIN;
INSERT INTO player(player_id, login, email, display_name, pass_hash, pass_salt)
VALUES (1, 'narrator', 'narrator@gateway.localhost', 'Narrator', ''::bytea, ''::bytea);
INSERT INTO persona(persona_id, persona_name)
VALUES (1, 'Narrator');
INSERT INTO player_group(player_group_id, player_group_name)
VALUES (1, 'Everyone');
INSERT INTO players_groups(player_id, player_group_id)
VALUES (1, 1);
INSERT INTO owners_borrowers(player_id, persona_id, is_owner)
VALUES (1, 1, TRUE);
COMMIT;
I've worked around the issue by not using CL-YESQL for executing multi-statement files, and instead depending on the freshly hacked https://github.com/phoe/postmodern-execute-file/ library for executing those.
I'm reopening this as I think this use case should be supported, perhaps with a @block
annotation.
While I'm intrigued to see that a Postgres parser in Lisp exists, Yesql is intended to be agnostic as to the SQL dialect used, so my first thought is to keep it simple and distinguish commands based on indentation.
It might need to be done per-database anyway due to the differences they have in transaction support.
I have a complex installation function that is composed of a
CREATE TABLE
and twoCREATE INDEX
statements:It seems that I am unable to execute them within one CL-YESQL transaction:
How should I proceed in this case? Should I create the transaction on the Lisp side and call the three individual subfunctions there?