reposilite-playground / exposed-upsert

Upsert DSL extension for Exposed, Kotlin SQL framework
The Unlicense
34 stars 3 forks source link

Unable to use column with reserved words such as "user" as conflict column. #9

Closed lammertw closed 1 year ago

lammertw commented 1 year ago

I have a table with a column named user (which contains an id referring to my own users table). In Postgres, user is a reserved word, which means it's required to put quotes around it when using it in SQL.

I have the following code:

UsageInfos.upsert(
    conflictColumn = UsageInfos.user,
    insertBody = {
        it[user] = id
        it[other] = "Value"
    },
    updateBody = {
        it[other] = "Value"
    }
)

Which results in the following SQL: INSERT INTO usageinfos ("other", "user") VALUES ('Value', 86) ON CONFLICT(user) DO UPDATE SET "other"='Value'

Because CONFLICT(user) is missing quotes, this results in an error.

The correct SQL should be: INSERT INTO usageinfos ("other", "user") VALUES ('Value', 86) ON CONFLICT("user") DO UPDATE SET "other"='Value'