Skip to content

Bug in sqlx.Named where ::text is incorrectly processed, leading to syntax erro #956

@KostyaDevelop

Description

@KostyaDevelop

Description:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions