Skip to content

Improper handling of to_timestamp times #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sbussard-inversemetric opened this issue Mar 20, 2025 · 2 comments
Open

Improper handling of to_timestamp times #1048

sbussard-inversemetric opened this issue Mar 20, 2025 · 2 comments

Comments

@sbussard-inversemetric
Copy link

Code

    await sql`
      INSERT INTO table_name
      ${sql(inputData)}
    `

Postgres.js debug output

SQL: 
    INSERT INTO table_name
    ("start_time")values($1)

Params: [ 'to_timestamp(3213213210)' ]
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

RangeError: Invalid time value
    at Date.toISOString (<anonymous>)
    at Object.serialize 

Direct postgres query
select to_timestamp(3213213210); => 2071-10-27 18:13:30.000 -0500

@sbussard-inversemetric
Copy link
Author

I'm a bit confused as to why Date.toISOString is being called under the hood instead of just using the value provided

@sbussard-inversemetric
Copy link
Author

Workaround is to use new Date(epochSeconds * 1000).toISOString() instead of wrapping the value (epoch seconds) in a postgres to_timestamp function.

Feel free to close if postgres.js does not intend to support calls to postgres functions as date values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant