Skip to content

multiple statements in one query #137

Open
@liverpool8056

Description

@liverpool8056

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';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions