Skip to content

pg JSON serialization is inconsistent with raw values serialization #1544

@shoooe

Description

@shoooe

In Postgres if you run:

SELECT now()::timestamptz;
SELECT to_json(now()::timestamptz);

you get different formats for timestamptz:

2025-08-10 14:44:40.687342+00
2025-08-10T14:44:40.687342+00:00

This can be surprising for new users as the same table may return two different formats for the same column depending on whether they are fetched from a regular select or in a JSON serialization context (e.g. jsonArrayFrom or jsonObjectFrom).

The proposal is to add an helper to set sensible defaults in pg.Client to make it so records fetched from jsonObjectFrom and regular selects return the same data in the same format.

💡 Ideally this would work in conjunction with kysely-codegen to make sure the types for e.g. timestamptz is string and not Date.

Original conversation: https://discord.com/channels/890118421587578920/1404035101880225864/1404096976605417562

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelpersRelated to library's helperspostgresRelated to PostgreSQL

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions