drizzle-team / drizzle-team/drizzle-orm

[BUG]: Materialized View without an `id` column results in an error

Open
#3,114 1 comment 0 reactions 0 assignees View on GitHub
bug bug/cant-reproduce db/postgres priority qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.32.0

### What version of `drizzle-kit` are you using?

0.23.0

### Describe the Bug

When querying from a materialized view defined with `pgMaterializedView` and when the materialized view doesn't contain a column named as `id`, any query against this materialized view results in the error: `column "id" does not exist`.

### Example

```ts
const myMaterializedView = pgMaterializedView("my_materialized_view").as((qb) =>
qb.select({ userId: anotherTable.userId, contentId: anotherTable.contentId }).from(anotherTable)
);

const result = await db.select().from(myMaterializedView);
```

_`userId` and `contentId` forms a composite primary key in `anotherTable`_

### Expected behavior

The query should work without an error.

### Environment & setup

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.