mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Fix PostgreSQL TIME and TIMETZ binary format handling (#22354)
## Summary - Fixes binary format handling for PostgreSQL TIME and TIMETZ data types - Resolves issue where time values were returned as garbled binary data with null bytes ## Problem When PostgreSQL returns TIME or TIMETZ columns in binary format, Bun.sql was not properly converting them from their binary representation (microseconds since midnight) to readable time strings. This resulted in corrupted output like `\u0000\u0000\u0000\u0000\u0076` instead of proper time values like `09:00:00`. ## Solution Added proper binary format decoding for: - **TIME (OID 1083)**: Converts 8 bytes of microseconds since midnight to `HH:MM:SS.ffffff` format - **TIMETZ (OID 1266)**: Converts 8 bytes of microseconds + 4 bytes of timezone offset to `HH:MM:SS.ffffff±HH:MM` format ## Changes - Added binary format handling in `src/sql/postgres/DataCell.zig` for TIME and TIMETZ types - Added `InvalidTimeFormat` error to `AnyPostgresError` error set - Properly formats microseconds with trailing zero removal - Handles timezone offsets correctly (PostgreSQL uses negative values for positive UTC offsets) ## Test plan Added comprehensive tests in `test/js/bun/sql/postgres-time.test.ts`: - [x] TIME and TIMETZ column values with various formats - [x] NULL handling - [x] Array types (TIME[] and TIMETZ[]) - [x] JSONB structures containing time strings - [x] Verification that no binary/null bytes appear in output All tests pass locally with PostgreSQL. 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,7 @@ pub const AnyPostgresError = error{
|
||||
InvalidQueryBinding,
|
||||
InvalidServerKey,
|
||||
InvalidServerSignature,
|
||||
InvalidTimeFormat,
|
||||
JSError,
|
||||
MultidimensionalArrayNotSupportedYet,
|
||||
NullsInArrayNotSupportedYet,
|
||||
@@ -90,6 +91,7 @@ pub fn postgresErrorToJS(globalObject: *jsc.JSGlobalObject, message: ?[]const u8
|
||||
error.InvalidQueryBinding => "ERR_POSTGRES_INVALID_QUERY_BINDING",
|
||||
error.InvalidServerKey => "ERR_POSTGRES_INVALID_SERVER_KEY",
|
||||
error.InvalidServerSignature => "ERR_POSTGRES_INVALID_SERVER_SIGNATURE",
|
||||
error.InvalidTimeFormat => "ERR_POSTGRES_INVALID_TIME_FORMAT",
|
||||
error.MultidimensionalArrayNotSupportedYet => "ERR_POSTGRES_MULTIDIMENSIONAL_ARRAY_NOT_SUPPORTED_YET",
|
||||
error.NullsInArrayNotSupportedYet => "ERR_POSTGRES_NULLS_IN_ARRAY_NOT_SUPPORTED_YET",
|
||||
error.Overflow => "ERR_POSTGRES_OVERFLOW",
|
||||
|
||||
Reference in New Issue
Block a user