postgres: Dynamic table queries are failing in v3

Trying to migrate to from v2 to v3 and all of my dynamic table queries are failing. From the logs the difference seems to be that dynamic attribute is missing, but I guess the API could have changed and it’s no longer needed?

await pg`SELECT * FROM ${pg('channel')};`

// v2.0.0-beta.11
// 5 SELECT * FROM "channel"; [ dynamic: true ]
// Works as expected…

// v3.2.4
// 28 SELECT * FROM "channel"; [] []
// PostgresError: relation "channel" does not exist

What’s interesting, if i pass along the table schema, then it also works…

await pg`SELECT * FROM ${pg('public.channel')};`
// 28 SELECT * FROM "public"."channel"; [] []
// Works as expected…

Any ideas what’s wrong with v3 and how to make it work without the public schema?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

I struggled with a related error. I finally fixed it by specifying the search path in the connection parameters instead of manually setting the search_path after the connection was created. In other words, I was doing this:

const initiateDb = async schema => {
  const sql = postgres(null, { ...connectionParams })
  await sql`set search_path=${schema}`
  return sql
}

…and changing it to this fixed the issue:

const initiateDb = async schema => {
  return postgres(null, { ...connectionParams, connection: { search_path: schema } })
}

I hope this helps save somebody some headache.

Well I had the best intentions of taking a look, but the time hasn’t come up yet 😦 … Hopefully I’ll find a hole soon, but if you figure anything out - let me know.