porsager / porsager/postgres

Dynamic columns in updates

Open
#799 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

trying to make an update with dynamic columns and i'm getting a bunch of errors

object
cliente: {

id: 3,
nome: 'Teste Um',
tipo: 'F',
cpf: '12345678910',
cnpj: null,
email: 'teste@black.com',
telefone: '46111111111',
status: 'A',
datacadastro: '2024-02-01'

}

query

const cols = ['nome', 'tipo', 'cpf', 'cnpj', 'email', 'telefone'];
const update = await sql`UPDATE clientes SET (${sql(cliente, cols)}) WHERE id=${sql(cliente.id)}`;

error: Cannot convert undefined or null to object

query 2 (removed the null fields)

const cols = ['nome', 'tipo', 'cpf', 'email', 'telefone'];
const update = await sql`UPDATE clientes SET (${sql(cliente, cols)}) WHERE id=${sql(cliente.id)}`;

error: syntax error at or near "$1"

query 3 (removed the () after SET)

const cols = ['nome', 'tipo', 'cpf', 'cnpj', 'email', 'telefone'];
const update = await sql`UPDATE clientes SET ${sql(cliente, cols)} WHERE id=${sql(cliente.id)}`;

error: syntax error at end of input

any thoughts?

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 three UPDATE examples using the sql helper and PostgreSQL, comparing the behavior of null values, the parenthesized SET expression, and the unparenthesized form. Done means establishing the supported dynamic-column syntax and documenting or correcting the failing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.