Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute sql strings with multiple statements #346

Open
kilianmh opened this issue Apr 19, 2024 · 3 comments
Open

Execute sql strings with multiple statements #346

kilianmh opened this issue Apr 19, 2024 · 3 comments

Comments

@kilianmh
Copy link
Contributor

In the psql cli we can execute two statements in one go. E.g.

CREATE TABLE test_table (user_id INTEGER NOT NULL PRIMARY KEY , user_name VARCHAR(256) NOT NULL);

CREATE INDEX idx_test_table_user_name
ON test_table (user_name);

Right now trying this with pomo:execute or pomo:query results in an error.

Do you think these macros could/should handle sql strings with multiple statements as well?
This would also allow to add more slots to dao class (e.g. col-index, col-comment).

I can help with the implementation if it helps.

@sabracrolleton
Copy link
Collaborator

I am a bit time constrained right now, so would be happy if you took a first look.

@kilianmh
Copy link
Contributor Author

kilianmh commented Apr 20, 2024

I guess we have to split the queries at one point with parse-queries to support multiple statements.

As I see it there are basically 3 options (probably there are more):

  1. Add an arg to query e.g. :multiple-statements
    When this arg is present, the query will be split.
    (not sure how to implement this)
  2. Split the query within an existing functions.
    Options are e.g. query (macro-function), exec-query (function), send-query (function)
    The performance will be slightly worse since parse-queries would be performed in all queries.
  3. Introduce new macros/functions (e.g. queries, execute-queries, orsend-queries) that split the query with parse-queries and call the existing functions.
    Downside is that we have to export more exported symbols and users need to know about them as well.

Which options sounds best to you, or you got another idea?

@sabracrolleton
Copy link
Collaborator

My initial preference would be #3 (I like singular and plural, but that is just me).

Probably need an arg for the user to decide if everything is wrapped in a single transaction or commits each separately.

Would we get back parameterization that we do not have in execute-file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants