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

[BUG] "FOR UPDATE must specify unqualified relation names" with .forUpdate([tbl]) and .withSchema(schema) #1324

Open
tlonny opened this issue Jan 17, 2025 · 2 comments
Labels
bug Something isn't working built-in plugin Related to a built-in plugin postgres Related to PostgreSQL

Comments

@tlonny
Copy link

tlonny commented Jan 17, 2025

forUpdate with specified table names causes a PG error if the query uses an explicit withSchema with error:

FOR UPDATE must specify unqualified relation names

Repro:

import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely"
import { Pool } from "pg"

interface FooTable { id : string }
interface BarTable { id : string }

export interface DB { 
    foo: FooTable, 
    bar: BarTable 
}

const connectionString = "postgres://postgres:password@localhost:5432/scratch" 
export const pool = new Pool({ connectionString })

const database = new Kysely<DB>({
    dialect: new PostgresDialect({ pool: pool }),
    plugins: [ new CamelCasePlugin() ]
})

const q = database
    .selectFrom("foo")
    .innerJoin("bar", "bar.id", "foo.id")
    .forUpdate(["foo"])
    .skipLocked()

console.log(q.compile().sql)

// select from "foo" inner join "bar" on "bar"."id" = "foo"."id" for update of "foo" skip locked

await q.execute()

const q2 = database
    .withSchema("public")
    .selectFrom("foo")
    .innerJoin("bar", "bar.id", "foo.id")
    .forUpdate(["foo"])
    .skipLocked()

console.log(q2.compile().sql)

// select from "public"."foo" inner join "public"."bar" on "public"."bar"."id" = "public"."foo"."id" for update of "public"."foo" skip locked

await q2.execute() // THIS ERRORS
await pool.end()

@igalklebanov igalklebanov added bug Something isn't working built-in plugin Related to a built-in plugin postgres Related to PostgreSQL labels Jan 17, 2025
@igalklebanov
Copy link
Member

Hey 👋

Thanks for raising this! 🙏

@koskimas
Copy link
Member

Yep, that's a bug. Here's a workaround for now. https://kyse.link/mj9c1

You can install HackityHackPlugin to your Kysely instance instead of using it per query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working built-in plugin Related to a built-in plugin postgres Related to PostgreSQL
Projects
None yet
Development

No branches or pull requests

3 participants