porsager / porsager/postgres

Partial query build giving string output

Open
#945 1 comment 1 reaction 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

Trying to build partial query while working with jsonb, but its printing string in inserted row:

exports.updateEntityLastCount = async ({ pairs, tournamentId }) => {
const keys = Object.keys(pairs);
const vals = Object.values(pairs).map(
(value, index) =>
((entity_last_count ->> ${keys[index]})::int + ${value})::text,
);
const keyArray = sql${keys.join(", ")};
const valArray = sql${vals.join(", ")};

return sql UPDATE tournaments SET entity_last_count = entity_last_count || jsonb_object( ARRAY[${keyArray}], ARRAY[${valArray}]) WHERE id = ${tournamentId};;
};

DB inserted row:
{"group": 1, "match": 1, "phase": "((entity_last_count ->> phase)::int + 1)::text", "bracket": 1}

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

Start at the exports.updateEntityLastCount entry point and reproduce the UPDATE against the jsonb entity_last_count column. Trace how the partial query values become the ARRAY arguments to jsonb_object, then verify that the phase value is stored as a number rather than the query expression text.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.