porsager / porsager/postgres

Replacing null from select result to default value

Open
#802 8 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

Hello there, I am trying to run multiple queries using sql.begin function, and some of the queries are undefined results, I want to replace those undefined with 0.

I tried this but had no success

   select COALESCE(status, 0) as count from mytable;

as a result when I try to loop into the results and access result[0].count I am getting
Cannot read properties of undefined (reading 'count')

Am I missing something?

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

The issue names no files or tests; start by reproducing the behavior through the sql.begin entry point with the shown COALESCE query. Inspect the returned result shape before result[0].count is accessed, and consider the work done when the expected handling of an undefined result is established and covered by a regression test or documentation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.