I've been trying to query PostgreSQL ltree. Here in table tree
, path
has type ltree
. I could write in psql:
SELECT id, path FROM tree WHERE path @ '12345'
with no problem. When I do in sqlx:
db.Get(&path, "SELECT id, path FROM tree WHERE path @ '$1'", entryID)
it keeps telling pq: operant syntax error
. Not sure if there's a way to properly escape single quote in the query string. I tried this but still doesn't work:
db.Get(&path, `SELECT id, path FROM tree WHERE path @ ''$1''`, entryID)
Turns out I don't need the single quote around $1 at all. This query would work:
db.Get(&path, `SELECT id, path FROM tree WHERE path @ $1`, entryID)