Skip to content

Wrong named query support #614

Closed
Closed

Description

@rafiwicht

Hi everyone

Description

First of thanks for the nice package. I have an issue when using the package with sqlx and PostgreSQL. When I use otelsql, sqlx detect the wrong driver type and named queries use ? instead of $1. It also doesn't help to use Rebind.

This doesn't work:

driverName, err := otelsql.Register("pgx",
  otelsql.WithAttributes(semconv.DBSystemNamePostgreSQL),
  otelsql.WithSpanOptions(otelsql.SpanOptions{
    Ping:           true,
    DisableErrSkip: true,
  }),
)
if err != nil {
  return nil, err
}

return sqlx.Open(driverName, config.DBURL), nil

This workaround works:

driverName, err := otelsql.Register("pgx",
  otelsql.WithAttributes(semconv.DBSystemNamePostgreSQL),
  otelsql.WithSpanOptions(otelsql.SpanOptions{
    Ping:           true,
    DisableErrSkip: true,
  }),
)
if err != nil {
  return nil, err
}

db, err := sql.Open(driverName, config.DBURL)
if err != nil {
  return nil, err
}

return sqlx.NewDb(db, "pgx"), nil

Environment

  • OS: Linux
  • Architecture: x86_64
  • Go Version: 1.25.6
  • otelsql version: v0.42.0

Steps To Reproduce

  1. Use the example from above

Expected behavior

It should work without the workaround.

Let me know what you think. I haven't really looked deeply in your code. If it's a small fix, I canm open an PR.

Best

Activity

  1. added
    bug
    on Mar 31, 2026
  2. XSAM commented on Apr 6, 2026

    @XSAM
    Owner

    Hey @rafiwicht, thanks for creating the issue!

    This is a known limitation of otelsql.Register because it returns a new driver name. sqlx has an internal hard-coded DB driver mapping that requires the exact driver name.

    https://github.com/jmoiron/sqlx/blob/41dac167fdad5e3fd81d66cafba0951dc6823a30/bind.go#L24-L29

    With a custom driver name, sqlx uses UNKNOWN as the bindtype, thus ? stays ?.

    https://github.com/jmoiron/sqlx/blob/41dac167fdad5e3fd81d66cafba0951dc6823a30/bind.go#L74-L81

    That is why otelsql provides other methods to address compatible issues like this.

    In your case, otelsql.Open + sqlx.NewDb(db, "pgx") should work for you.

    I will update the doc of otelsql.Register to make this limitation clearer.

  3. added a commit that references this issue on Apr 6, 2026
  4. added this to the v0.43.0 milestone on Apr 30, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions