Using ${…} breaks DatabaseClient?

This is failing with Error: bind message supplies 1 parameters, but prepared statement "" requires 0:

db.sql` SELECT * FROM status_view WHERE "deviceId" = '${device_id}'`
// using db = DatabaseClient("db")

I need the quotes on deviceId because that is the column name (and yes, I’m aware it shouldn’t be so in Postgres… it is what it is).

If I manually supply a device_id as text the query works fine.

Why is it acting like this? Is this intended?

This also fails if I “precompile” the string as sql and attempt to only supply the precompiled string like…

db.sql`${sql}`

In this case the error is Error: syntax error at or near "$1"

The solution is that I don’t need to manually single-quote strings!

3 Likes