porsager / porsager/postgres

Bigint values are converted to string in JSON

Open
#1,182 1 comment 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

I have window function which uses ROW_NUMBER. It returns bigint, but postgres.js converts it into a string. However, id field, which is int, is, in fact, a number in JSON:

SELECT row_number() over (order by id) * 100 as row_num,
       id
FROM clients.client;
Image

PostgreSQL shows that row_num is bigint and id is int:

Image

If I explicitly convert to int, then all goes fine:

SELECT (row_number() over (order by id) * 100) :: int as row_num,
       id
FROM clients.client;
Image

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 tracing PostgreSQL type decoding for bigint and compare it with int results for the shown ROW_NUMBER query. Clarify the expected JSON representation, then add a regression test for the query and verify that the agreed behavior is consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.