jackc/pgx · error

composite text format unterminated quoted field

Error message

composite text format unterminated quoted field

What it means

Returned by CompositeTextScanner.Next while parsing a double-quoted field: the input ended before the closing quote was found, leaving an unterminated quoted field. A quote or escape consumed the final ')' without closing the value.

Solutions

  1. Fix the composite literal so every quoted field is terminated
  2. Check for truncation of the value in transit
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/composite.go:414 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/bc79184fbc8eb2b1. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/composite.go:414

	if cfs.rp >= len(cfs.src) {
		return false
	}

	switch cfs.src[cfs.rp] {
	case ',', ')': // null
		cfs.rp++
		cfs.fieldBytes = nil
		return true
	case '"': // quoted value
		cfs.rp++
		cfs.fieldBytes = make([]byte, 0, 16)
	quotedValue:
		for {
			// A quote or escape may have consumed the final ')', leaving an
			// unterminated quoted field.
			if cfs.rp >= len(cfs.src) {
				cfs.err = fmt.Errorf("composite text format unterminated quoted field")
				return false
			}
			ch := cfs.src[cfs.rp]

			switch ch {
			case '"':
				cfs.rp++
				if cfs.rp < len(cfs.src) && cfs.src[cfs.rp] == '"' {
					cfs.fieldBytes = append(cfs.fieldBytes, '"')
					cfs.rp++
				} else {
					break quotedValue
				}
			case '\\':
				cfs.rp++
				if cfs.rp >= len(cfs.src) {
					cfs.err = fmt.Errorf("composite text format unterminated quoted field")
					return false

View on GitHub (pinned to ec1a0befd2)