drizzle-team / drizzle-team/drizzle-orm
[BUG]:
- 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.30.9
### What version of `drizzle-kit` are you using?
0.20.17
### Describe the Bug
I have declared the following view:
```typescript
export const AssetPriceLevelIntervalsView = pgView(
"asset_price_level_intervals",
).as((qb) =>
qb
.select({
interval:
sql`PERCENTILE_CONT(0.33) WITHIN GROUP (ORDER BY (kg_price * percent_in_formula))`.as(
"interval",
),
})
.from(Asset)
.union(
qb
.select({
interval:
sql`PERCENTILE_CONT(0.66) WITHIN GROUP (ORDER BY (kg_price * percent_in_formula))`.as(
"interval",
),
})
.from(Asset),
),
);
```
I didn't find a clear place in the docs indicating how to select from this view but I assumed (and the typescript types) made me infer that the correct way to select from it would be:
```typescript
const viewResults = await db
.select()
.from(AssetPriceLevelIntervalsView);
```
That does work in development when I use next `--turbo` mode and it compiles fast but it only work the 1st time. After I save some file and the development watch mode triggers a rebuild the view stops working.
The query that it calls the first time is this:
After rebuild when it runs the second time it fails and the query it logs is this one:
It also spits this error:
It's also worth noticing that I managed to put it to work by calling the view using the `sql` tool like this:
```typescript
const result = await db
.select({
interval: AssetPriceLevelIntervalsView.interval,
})
.from(
sql`asset_price_level_intervals`
);
```
### Expected behavior
It should run the select normally like it does from a pgTable isntance
### Environment & setup
Next.js 14, running `next dev --turbo`. The database is postgres.
I'd be happy to provide more context on this...
Contributor guide
Assessment
This issue has not been assessed yet.