Skip to content

[BUG]: Cannot query tables without underscores #4154

@RAGessler

Description

@RAGessler

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.39.3

What version of drizzle-kit are you using?

0.30.4

Other packages

drizzle-seed 0.3.0

Describe the Bug

When querying a table that does not have an underscore in the table name eg: "users" the query will fail with an error.

Schema:

export const exampleSchema = pgSchema("example");

export const users = exampleSchema.table("users", {
  id: bigint({ mode: "number" }).primaryKey().generatedAlwaysAsIdentity(),
  firstName: varchar("user_name", { length: 25 }),
});

Query:

 const db = drizzle(process.env.DATABASE_URL!, {
  schema: { users, posts, comments },
  casing: "snake_case",
});

const main = async () => {
  const result = await db.query.users.findFirst();
  console.log(result);
};
main();

Results in error:

error: relation "users" does not exist
    at /Users/rgessler/fo-drizzle-my-nizzle/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at <anonymous> (/Users/rgessler/fo-drizzle-my-nizzle/node_modules/src/node-postgres/session.ts:104:19)
    at main (/Users/rgessler/fo-drizzle-my-nizzle/src/index.ts:5:18) {
  length: 104,
  severity: 'ERROR',
  code: '42P01',
  detail: undefined,
  hint: undefined,
  position: '31',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_relation.c',
  line: '1449',
  routine: 'parserOpenTable'
}

However
Changing the table name in the schema from "users" to "users_" results in a successful query return. It also seems that this bug started in version 0.39.1 as I've reverted to 0.39.0 as a temporary solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions