jackc/pgx · error

expected statement description, got %T

Error message

expected statement description, got %T

What it means

While preparing statements in a batch pipeline, a result retrieved after Sync was not a *pgconn.StatementDescription as required. This indicates a protocol-level desynchronization or an unexpected response from the server during batch prepare.

Solutions

  1. Inspect the actual type reported by %T to identify which protocol message arrived instead
  2. Check for a mismatch between pgx and PostgreSQL server versions
  3. Report as a bug if reproducible with a supported server version
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at conn.go:1207 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/ec7b992143d4ee53. Report an issue: GitHub.

Appendix: source

Thrown at conn.go:1207

						sdCache.Invalidate(sd.SQL)
					}
				}
			}()

			err = pipeline.Sync()
			if err != nil {
				return err
			}

			for _, sd := range distinctNewQueries {
				results, err := pipeline.GetResults()
				if err != nil {
					return newErrPreprocessingBatch("prepare", sd.SQL, err)
				}

				resultSD, ok := results.(*pgconn.StatementDescription)
				if !ok {
					return fmt.Errorf("expected statement description, got %T", results)
				}

				// Fill in the previously empty / pending statement descriptions.
				sd.ParamOIDs = resultSD.ParamOIDs
				sd.Fields = resultSD.Fields
			}

			results, err := pipeline.GetResults()
			if err != nil {
				return err
			}

			_, ok := results.(*pgconn.PipelineSync)
			if !ok {
				return fmt.Errorf("expected sync, got %T", results)
			}

			return nil

View on GitHub (pinned to ec1a0befd2)