jackc/pgx · error

Stmt.Exec deprecated and not implemented

Error message

Stmt.Exec deprecated and not implemented

What it means

stdlib Stmt.Exec implements database/sql's deprecated single-round-trip Exec hook, which pgx deliberately does not support: it always returns this error. Any call is a faulty-input situation — modern database/sql always uses ExecContext instead, so hitting it means an old driver or direct invocation.

Solutions

  1. Use Stmt.ExecContext instead of Stmt.Exec; ExecContext is implemented and delegates to conn.ExecContext with the statement's SQL and named arguments.
  2. Retrieve the underlying SQL via s.sd.SQL and execute it directly through the *sql.DB or *sql.Conn handle.
  3. If implementing a driver.Stmt, note pgx deliberately does not support the deprecated Exec path.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at stdlib/sql.go:612 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /api/errors/bce223463ed2711e. Report an issue: GitHub.

Appendix: source

Thrown at stdlib/sql.go:612

	defer cancel()

	refCount := s.conn.psRefCounts[s.sd]
	if refCount == 1 {
		delete(s.conn.psRefCounts, s.sd)
	} else {
		s.conn.psRefCounts[s.sd]--
		return nil
	}

	return s.conn.conn.Deallocate(ctx, s.sd.SQL)
}

func (s *Stmt) NumInput() int {
	return len(s.sd.ParamOIDs)
}

func (s *Stmt) Exec(argsV []driver.Value) (driver.Result, error) {
	return nil, errors.New("Stmt.Exec deprecated and not implemented")
}

func (s *Stmt) ExecContext(ctx context.Context, argsV []driver.NamedValue) (driver.Result, error) {
	return s.conn.ExecContext(ctx, s.sd.SQL, argsV)
}

func (s *Stmt) Query(argsV []driver.Value) (driver.Rows, error) {
	return nil, errors.New("Stmt.Query deprecated and not implemented")
}

func (s *Stmt) QueryContext(ctx context.Context, argsV []driver.NamedValue) (driver.Rows, error) {
	return s.conn.QueryContext(ctx, s.sd.SQL, argsV)
}

type rowValueFunc func(src []byte) (driver.Value, error)

type Rows struct {
	conn         *Conn

View on GitHub (pinned to ec1a0befd2)