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

multiple statements in one query #137

Open
liverpool8056 opened this issue Mar 4, 2023 · 2 comments
Open

multiple statements in one query #137

liverpool8056 opened this issue Mar 4, 2023 · 2 comments

Comments

@liverpool8056
Copy link

liverpool8056 commented Mar 4, 2023

Hi
I found when sending multiple statements separated by ';\n' in one query, they will be included in one single transaction on Postgres. And I tried to do the similar thing via plsql or Java JDBC Framework , these statements will be separated into different transactions respectively. I just want to confirm if it is as expected?

ENV: pgmoon 1.16.0-1

Here is my test case:

local pgmoon = require("pgmoon")
local pg = pgmoon.new({
  host = "127.0.0.1",
  port = "5432",
  database = "db",
  user = "dbuser",
  password = "pass",
})

assert(pg:connect())

statements = [[
DELETE FROM "events" WHERE "expire_at" < CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
DELETE FROM "audit_log" WHERE "ttl" < CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
]]

assert(pg:query(statements))

The query log output on Postgres:

STATEMENT:    DELETE FROM "events" WHERE "expire_at" < CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
	  DELETE FROM "audit_log" WHERE "ttl" < CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
@leafo
Copy link
Owner

leafo commented Apr 27, 2023

This is expected, this is functionality of the postgres simple query protocol. If you use the extended protocol then you can only issue one query at a time.

@liverpool8056
Copy link
Author

@leafo Thank you!

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