jackc/pgx · error

unexpected DataRow message without preceding RowDescription

Error message

unexpected DataRow message without preceding RowDescription

What it means

A DataRow message arrived from the backend while reading batch results, but no RowDescription preceded it in the current result set. This means the message stream is out of order — a protocol violation or internal bookkeeping bug. The multi-result reader records the error and stops.

Solutions

  1. Verify server compatibility (PostgreSQL or wire-compatible server)
  2. Check for middleware/proxies that reorder or inject messages
  3. Report as a bug with a reproduction if using standard PostgreSQL
  4. Inspect the batch structure for malformed queued queries
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pgconn/pgconn.go:1657 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/9b8a48ff8c0df531. Report an issue: GitHub.

Appendix: source

Thrown at pgconn/pgconn.go:1657

				mrr.statementDescriptions = mrr.statementDescriptions[1:]

				resultFormats := mrr.resultFormats[0]
				mrr.resultFormats = mrr.resultFormats[1:]

				sdFields := sd.Fields
				rr.fieldDescriptions = rr.pgConn.getFieldDescriptionSlice(len(sdFields))

				err := combineFieldDescriptionsAndResultFormats(rr.fieldDescriptions, sdFields, resultFormats)
				if err != nil {
					rr.concludeCommand(CommandTag{}, err)
				}

				mrr.pgConn.resultReader = rr
				mrr.rr = &mrr.pgConn.resultReader
				return true
			}

			mrr.err = fmt.Errorf("unexpected DataRow message without preceding RowDescription")
			return false
		}

		msg, err := mrr.receiveMessage()
		if err != nil {
			return false
		}

		switch msg := msg.(type) {
		case *pgproto3.RowDescription:
			mrr.pgConn.resultReader = ResultReader{
				pgConn:            mrr.pgConn,
				multiResultReader: mrr,
				ctx:               mrr.ctx,
				fieldDescriptions: mrr.pgConn.getFieldDescriptionSlice(len(msg.Fields)),
			}
			convertRowDescription(mrr.pgConn.resultReader.fieldDescriptions, msg)

View on GitHub (pinned to ec1a0befd2)