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]:SQL index against reserved column names omit quotes #2484

Open
Aymericr opened this issue Jun 10, 2024 · 0 comments
Open

[BUG]:SQL index against reserved column names omit quotes #2484

Aymericr opened this issue Jun 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Aymericr
Copy link

What version of drizzle-orm are you using?

0.31.1

What version of drizzle-kit are you using?

0.22.2

Describe the Bug

Notice the use of "user" as a column name:

export const customers = pgTable(
  "customers",
  {
    id: id("customer"),
    user: text("user").references(() => users.id, {
      onDelete: "set null",
    }),
    organization: text("organization")
      .notNull()
      .references(() => organizations.id, { onDelete: "cascade" }),
  },
  (table) => ({
    customer_user_organization_idx: uniqueIndex().on(
      table.user,
      table.organization,
    ),
  }),
)

Generates the following SQL:

CREATE UNIQUE INDEX IF NOT EXISTS "customers_user_organization_index" ON "customers" USING btree (user,organization);--> statement-breakpoint

Which yield the following error:

ERROR:  functions in index expression must be marked IMMUTABLE

Expected behavior

Should generate the following SQL:

CREATE UNIQUE INDEX IF NOT EXISTS "customers_user_organization_index" ON "customers" USING btree ("user",organization);--> statement-breakpoint

Environment & setup

No response

@Aymericr Aymericr added the bug Something isn't working label Jun 10, 2024
@Aymericr Aymericr changed the title [BUG]:Index against reserved column names omit quotes [BUG]:SQL index against reserved column names omit quotes Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant