Query View syntax error at or near "$1"

I've declared my view like such
export const myView = pgView("my_view", {
{my fields}
}).existing();
export const myView = pgView("my_view", {
{my fields}
}).existing();
And then when i query my view
const results = await db.select().from(myView)
const results = await db.select().from(myView)
I get the syntax error When printing out the sql of it via
const results = await db.select().from(myView).toSQL()
const results = await db.select().from(myView).toSQL()
Gives me these results
{
sql: "select from $1",
params: [
r {
[Symbol("drizzle:ViewBaseConfig")]: {
name: "my_view",
originalName: "my_view",
schema: undefined,
selectedFields: {
my fields
},
query: undefined,
isExisting: true,
isAlias: false
},
[Symbol("drizzle:PgViewConfig")]: undefined
}
]
}
{
sql: "select from $1",
params: [
r {
[Symbol("drizzle:ViewBaseConfig")]: {
name: "my_view",
originalName: "my_view",
schema: undefined,
selectedFields: {
my fields
},
query: undefined,
isExisting: true,
isAlias: false
},
[Symbol("drizzle:PgViewConfig")]: undefined
}
]
}
What am i missing? Any direction would be greatly appreciated 🙏 Im on drizzle orm version 0.30.9
1 Reply
joshpachner
joshpachnerOP7mo ago
I should add, normal querying against tables via the
db.query.<tableName>.findMany(...)
db.query.<tableName>.findMany(...)
does work fine if i toggle it from a
pgView("my_view",{...)
pgView("my_view",{...)
to
pgTable("my_view",{...)
pgTable("my_view",{...)
it works Ok I found the issue, and i will keep my post here for my shame and in hopes it helps someone else. I didnt realize that my drizzle-orm/postgres-js was still on version 0.28.6 (im using Deno so its kinda funky how they do the imports) Anyways, once i upgraded them all to version 0.30.9, it now queries as expected
Want results from more Discord servers?
Add your server