serverless icon indicating copy to clipboard operation
serverless copied to clipboard

pg is outdated

Open johanneskares opened this issue 10 months ago • 6 comments

Node Postgres version is quite outdated form more than 2 years ago:

https://github.com/neondatabase/serverless/blob/6bf306b6789d719f157a9e3fa040ed2679c3bfc7/package.json#L94

johanneskares avatar Feb 11 '25 15:02 johanneskares

That's true, and it's been on my hypothetical TODO list for a while to update. But it's not trivial, because we shim quite a few internals in a way that I know will need to change.

Are there any particular features or fixes you need that the latest version has?

jawj avatar Feb 11 '25 16:02 jawj

I just came to request bump to the latest pg release v8.13.2 from today which includes fix for https://github.com/brianc/node-postgres/issues/3373 ("Cannot set property message of #<_ErrorEvent> which has only a getter" on connection timeout).

Didn't realise it would be more of a major change to update but understand the situation. I'm currently applying this to the bundled pg via a patch so purely noting here in case it helps anyone else - I'm not blocked.

andyjy avatar Feb 11 '25 21:02 andyjy

Currently, with this old version, timestamps are returned as strings while date's are returned as JS Dates. I believe this default behavior was changed in a more recent version of pg and tools like kysely typegen expect both to be returned as Dates.

johanneskares avatar Feb 12 '25 22:02 johanneskares

@johanneskares I don't think that's right:

> pool.query('SELECT now()::timestamptz').then(r => console.log(r.rows[0].now.constructor.name))
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 633,
  [Symbol(trigger_async_id_symbol)]: 609
}
> Date

> pool.query('SELECT now()::timestamp').then(r => console.log(r.rows[0].now.constructor.name))
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 758,
  [Symbol(trigger_async_id_symbol)]: 734
}
> Date

> pool.query('SELECT now()::date').then(r => console.log(r.rows[0].now.constructor.name))
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 862,
  [Symbol(trigger_async_id_symbol)]: 860
}
> Date

jawj avatar Apr 23 '25 14:04 jawj

Timestampz are definitely coming out as dates, unless you configure the driver to return strings:

    const { types } = require('@neondatabase/serverless');
    types.setTypeParser(types.builtins.TIMESTAMPTZ, (s: string) => s);
    types.setTypeParser(types.builtins.TIMESTAMP, (s: string) => s);
    types.setTypeParser(types.builtins.DATE, (s: string) => s);
    types.setTypeParser(types.builtins.TIME, (s: string) => s);
    types.setTypeParser(types.builtins.TIMETZ, (s: string) => s);

I know because I had both in my project, with React RSC keeping backend string-ly and moving date-conversion to the frontend just makes more sense. (related: https://github.com/better-auth/better-auth/pull/4298)

steipete avatar Aug 29 '25 03:08 steipete

Related: https://github.com/neondatabase/serverless/issues/180 since the requirement doesn't match the usage.

Icantjuddle avatar Oct 29 '25 19:10 Icantjuddle