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

feat(pg): allow creating indexes on 3+ columns mixing columns and expressions #2574

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lbguilherme
Copy link

Previously this would fail:

export const TestTable = pgTable(
  'TestTable',
  {
    id: uuid('id').defaultRandom().primaryKey().notNull(),
    foo: text('foo'),
    bar: text('bar'),
    json: jsonb('json'),
  },
  table => {
    return {
      idx: index('idx').using(
        'btree',
        table.foo,
        sql`(${table.json}->>'id')`,
        table.bar, // error!
      ),
    };
  },
);

Starting from the second argument, every index expression must be a column or all of them must be SQL expressions, they can't mix. This is a typing error.

As a workaround, it is possible to do this:

      idx: index('idx').using(
        'btree',
        table.foo,
        sql`(${table.json}->>'id')`,
        sql`${table.bar}`, // redundant, but ok
      ),

This patch fixes the typing.

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

Successfully merging this pull request may close these issues.

None yet

1 participant