-
-
Notifications
You must be signed in to change notification settings - Fork 106
Open
Description
Describe the bug
With native psql + knex, when querying a table with jsonb columns, the resulting rows deserialize the data into an object instead of a string. This causes jest to fail with queries that select jsonb. The same also happens with bigint where the value as returned by knex is string with psql but is a number with pg-mem.
Example failure diff generated by jest:
- Expected - 22
+ Received + 7
Object {
- "created_at": "2025-08-04T19:35:53.957Z",
- "extras": Object {
- "deripio": "h",
- "vito": "e",
- },
+ "created_at": 2025-08-04T19:35:53.957Z,
+ "extras": "{\"deripio\":\"h\",\"vito\":\"e\"}",
"fcm_token": "colo utrimque creo temeritas sto tenuis adduco caveo uterq
ue thorax",
- "id": "581042995298846",
+ "id": 581042995298846,
"id_token": "Administratio aetas velut ara perferendis barba quas. Verus
ipsam colligo volubilis. Comburo tunc exercitationem aperiam nobis.",
- "last_updated_at": "2025-07-26T12:44:05.531Z",
+ "last_updated_at": 2025-07-26T12:44:05.531Z,
"phone_number": "+16155297995",
- "profile": Object {
- "comparo": "G",
- },
+ "profile": "{\"comparo\":\"G\"}",
"profile_updated_at": null,
- "summary": Object {
- "odio": "P",
- "pecto": "F",
- "universe": "J",
- },
- "tags": Object {
- "tags": Array [
- "valens",
- "utilis",
- "uterque",
- ],
- },
+ "summary": "{\"pecto\":\"F\",\"odio\":\"P\",\"universe\":\"J\"}",
+ "tags": "{\"tags\":[\"valens\",\"utilis\",\"uterque\"]}",
}To Reproduce
Minimal example using knex:
export async function createAndSeedTable() {
await knex.schema.createTable('worker', async (table) => {
table.specificType('id', 'BIGSERIAL').primary();
table.jsonb('profile').notNullable().index();
table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable().index();
});
const worker = {
"id": "1",
"profile": { "name": "John Doe" },
"created_at": "2025-07-26T12:44:05.531Z",
};
const insertedRecord = await knex('worker').insert(worker).returning('*');
console.log(typeof insertedRecord.id) // "number"
console.log(typeof insertedRecord.profile) // "string"
}pg-mem version
3.0.5
Metadata
Metadata
Assignees
Labels
No labels