porsager / porsager/postgres

INSERT multiple sets optional boolean values to all null if first element is null

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

const equipmentList = 
[{
    someKey: "value1",
    optionalBool: null
  },
  {
    someKey: "value2",
    optionalBool: true
  },
  {
    someKey: "value3",
    optionalBool: false
  }]

await sql`insert into equipment ${sql(listOfThings)}` 

Because we used implicit columns and the first element has a null value, the resulting db table winds up with all optionalBool values as null. If the first element has a boolean for optionalBool, the column is saved correctly.

Version 3.4.3

We've worked around it but thought I should report it.

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 file or test is named in the report. Start by reproducing the shown implicit-column insert with the three equipment objects against PostgreSQL, then trace the insert value inference for a leading null. Done means the boolean column preserves null, true, and false per row; add a regression test if the existing test structure is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
backend, 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.