jackc/pgx · error

invalid format for tid

Error message

invalid format for tid

What it means

After stripping the outer parentheses of a tid literal, no ',' could be found to split the block number from the offset number (strings.Cut found no separator). The input is not in the "(block,offset)" form.

Solutions

  1. Ensure the tid literal contains a comma between block and offset
  2. Validate the format before scanning
  3. Re-obtain the ctid from the database rather than constructing it manually
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/tid.go:215 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/ddc0181f9fb59ef5. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/tid.go:215

	})
}

type scanPlanTextAnyToTIDScanner struct{}

func (scanPlanTextAnyToTIDScanner) Scan(src []byte, dst any) error {
	scanner := (dst).(TIDScanner)

	if src == nil {
		return scanner.ScanTID(TID{})
	}

	if len(src) < 5 {
		return fmt.Errorf("invalid length for tid: %v", len(src))
	}

	block, offset, found := strings.Cut(string(src[1:len(src)-1]), ",")
	if !found {
		return fmt.Errorf("invalid format for tid")
	}

	blockNumber, err := strconv.ParseUint(block, 10, 32)
	if err != nil {
		return err
	}

	offsetNumber, err := strconv.ParseUint(offset, 10, 16)
	if err != nil {
		return err
	}

	return scanner.ScanTID(TID{BlockNumber: uint32(blockNumber), OffsetNumber: uint16(offsetNumber), Valid: true})
}

func (c TIDCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
	return codecDecodeToTextFormat(c, m, oid, format, src)
}

View on GitHub (pinned to ec1a0befd2)