Skip to content

sqlx.Named fails when a named parameter is immediately followed by a PostgreSQL cast #983

Description

@ludenyo

Version

github.com/jmoiron/sqlx v1.4.0

Summary

sqlx.Named appears to misparse PostgreSQL cast syntax when it is attached directly to a named parameter, for example :boundary::jsonb.

Actual Behavior

The call returns:

err=unexpected ':' while reading named param at 16

Expected Behavior

The query should bind successfully, preserving the PostgreSQL cast, producing something equivalent to:

SELECT ?::jsonb AS boundary, '2026-05-01'::timestamptz AS starts_at;

with one bound argument for boundary.

Minimal Reproduction

package main

import (
    "fmt"

    "github.com/jmoiron/sqlx"
)

func main() {
    query := "SELECT :boundary::jsonb AS boundary, '2026-05-01'::timestamptz AS starts_at;"
    q, args, err := sqlx.Named(query, map[string]any{
        "boundary": `{"type":"Polygon","coordinates":[]}`,
    })

    fmt.Printf("query=%q\nargs=%#v\nerr=%v\n", q, args, err)
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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