question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translate pg sql NULL to javascript undefined

See original GitHub issue

I don’t know, maybe current translation NULL to null have some reasons, but from my point of view undefined is more useful, because undefined omitted in JSON automatically:

JSON.stringify({ x: null }) // {"x":null}
JSON.stringify({ x: undefined }) // {}

@brianc What do you think about it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:20
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
charmandercommented, Apr 25, 2017

I use null as an intentional “nothing” value, since undefined tends to be a mistake (given it’s what you get by reading a property that doesn’t exist).

Strongly −1 on implementing this, as a setting or otherwise.

4reactions
brianccommented, Apr 26, 2017

I don’t think it’s a bad idea at all, but it has potential to be a very subtle very breaking change if people are relying on strict equality checks for null on some of their query results. I think at this point we should consider the ship sailed on using null instead of undefined for result values & then if you want to strip them off in your own app you could do something like rows.map(row => _.omit(row, (val, key) => val === null or something? That’s a kinda unfortunate side-effect of having two empty values in JavaScript.

I tagged to version 7.x so I can think about it when I start working on some backwards incompat changes to the next breaking version…but I’m leaning towards “that is how it is” right now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to insert undefined value as null for pg node js
you can define a undefined variable using || operator. Ex var a ; var b = a || null;.
Read more >
How NULL and empty strings are treated in PostgreSQL vs ...
Oracle reads empty strings as NULLs, while PostgreSQL treats them as empty. Concatenating NULL values with non-NULL characters results in ...
Read more >
Cannot convert undefined or null to Object in JavaScript
The "Cannot convert undefined or null to Object" error occurs when we pass a null or an undefined value to a function that...
Read more >
node-mssql | Microsoft SQL Server client for Node.js
undefined and NaN values are automatically converted to null values. Example. request.input('input_parameter', ...
Read more >
Documentation: 8.2: PostgreSQL Error Codes
Error Code Meaning Constant 00000 SUCCESSFUL COMPLETION successful_completion 01000 WARNING warning 0100C DYNAMIC RESULT SETS RETURNED dynamic_result_sets_returned
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found