{"id":"fe89da4b36f5fdb9","repo":"jackc/pgx","slug":"cannot-unmarshal-s-to-timestamp-with-layout-s-or","errorCode":null,"errorMessage":"cannot unmarshal %s to timestamp with layout %s or %s (%w)","messagePattern":"cannot unmarshal (.+?) to timestamp with layout (.+?) or (.+?) \\(%w\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/timestamp.go","lineNumber":127,"sourceCode":"\t\t*ts = Timestamp{Valid: true, InfinityModifier: Infinity}\n\tcase \"-infinity\":\n\t\t*ts = Timestamp{Valid: true, InfinityModifier: -Infinity}\n\tdefault:\n\t\t// Parse time with or without timezone\n\t\ttss := *s\n\t\t// PostgreSQL uses ISO 8601 without timezone for to_json function and casting from a string to timestamp\n\t\ttim, err := time.Parse(time.RFC3339Nano, tss)\n\t\tif err == nil {\n\t\t\t*ts = Timestamp{Time: tim, Valid: true}\n\t\t\treturn nil\n\t\t}\n\t\ttim, err = time.ParseInLocation(jsonISO8601, tss, time.UTC)\n\t\tif err == nil {\n\t\t\t*ts = Timestamp{Time: tim, Valid: true}\n\t\t\treturn nil\n\t\t}\n\t\tts.Valid = false\n\t\treturn fmt.Errorf(\"cannot unmarshal %s to timestamp with layout %s or %s (%w)\",\n\t\t\t*s, time.RFC3339Nano, jsonISO8601, err)\n\t}\n\treturn nil\n}\n\ntype TimestampCodec struct {\n\t// ScanLocation is the location that the time is assumed to be in for scanning. This is different from\n\t// TimestamptzCodec.ScanLocation in that this setting does change the instant in time that the timestamp represents.\n\tScanLocation *time.Location\n}\n\nfunc (*TimestampCodec) FormatSupported(format int16) bool {\n\treturn format == TextFormatCode || format == BinaryFormatCode\n}\n\nfunc (*TimestampCodec) PreferredFormat() int16 {\n\treturn BinaryFormatCode\n}","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/timestamp.go#L109-L145","documentation":"Error \"cannot unmarshal %s to timestamp with layout %s or %s (%w)\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgtype/timestamp.go:127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}