porsager / porsager/postgres

Improper handling of `to_timestamp` times

Open
#1,048 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the SQL-template example and trace the serialization path shown at Object.serialize, comparing it with the direct PostgreSQL to_timestamp query. Done means the reported input no longer raises RangeError and its database behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.