You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug in sqlx.Named where ::text is incorrectly processed, leading to syntax erro #956
I encountered a bug while using sqlx.Named to bind query parameters in SQL queries that contain type casting (::text). The ::text syntax is being modified during the query parameter binding, causing the colon (:) to be removed. This leads to a syntax error in the SQL query.
Steps to Reproduce:
Use ::text in a SQL query for type casting in PostgreSQL.
Bind parameters using sqlx.Named.
The resulting query will have the colon (:) removed before text, causing a syntax error.
Example code:
companyId := 555
query := `SELECT DISTINCT
t.path::text AS catalog_path
WHERE t.company_id = :company_id
FROM table AS t`
params := map[string]interface{}{
"company_id": companyId,
}
query, args, err := sqlx.Named(query, params)
Resulting Query After sqlx.Named:
SELECT DISTINCT
t.path:text AS catalog_path
WHERE t.company_id = :company_id
FROM table AS t
Error Encountered:
pq: syntax error at or near ":"
Expected Behavior:
The ::text type cast should remain unchanged in the query, and the parameter binding should work as expected.
Actual Behavior:
The colon (:) before text is removed, resulting in an invalid SQL query and a syntax error.
Activity
javierbarboza commentedon Dec 19, 2024
can you change ::text for ::::text? this is working for me
mskhviyu commentedon Jan 18, 2025
you can use
cast(t.path as text) as catalog_pathinstead oft.path::text AS catalog_pathrowanseymour commentedon Oct 10, 2025
FYI this is fixed in https://github.com/vinovest/sqlx/ which uses a real parser and not regexes
suiriass commentedon Jun 18, 2026
Had the same problem. sqlex fixes this — drop-in replacement, works with ::text out of the box. https://github.com/go-sqlex/sqlex