Skip to content

Fix CSV export of missing properties - #2934

Open
yuexihuanchen wants to merge 2 commits into
AlaSQL:developfrom
yuexihuanchen:fix-csv-missing-properties-369
Open

yuexihuanchen wants to merge 2 commits into
AlaSQL:developfrom
yuexihuanchen:fix-csv-missing-properties-369

Conversation

@yuexihuanchen

@yuexihuanchen yuexihuanchen commented Oct 30, 2026 •

Copy link
Copy Markdown

Summary

  • Export missing properties and null values as empty CSV fields instead of the strings "undefined" or "null".
  • Preserve explicit "undefined" and "null" string values.
  • Add regression coverage for uneven rows and for null beside the literal string 'null'.

Tests

  • sh build.sh
  • npx --yes bun test --dots --preload ./test/bun-setup.js ./test/test-csv-missing-properties.js ./test/test369.js ./test/test176.js — 14 passed.
  • Manually verified null versus 'null' with default quoting and quote: ''.
  • The latest full local run had 16 known Windows path handling failures in test107-B.js / test2149.js and 5 external-network failures in test2112.js / test418.js; network failures vary between runs. No CSV regression tests failed.

Closes #369

Disclosure: This contribution was prepared with AI assistance (Kimi).

@mathiasrw mathiasrw added this to the v5.0.0 milestone Oct 31, 2026
@fixfon

fixfon commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

A null value still comes out as the quoted string "null":

alasql('SELECT * INTO CSV({headers:true, utf8Bom:false}) FROM ?', [[{a: 1, b: null}]]);
// '"a";"b"\r\n1;"null"\r\n'

With this change a missing property and a SQL NULL (SELECT NULL AS b, or a NULL stored with INSERT) both export as an empty field, but a JS null, which is what JSON input usually has, does not. It also can't be told apart from the real string 'null'. With quote: '' it prints null.

Checking s == null instead of s === undefined would cover both. A test row with null next to the string 'null' would pin it.

Ran on 576180d with Node 24 and compared with develop 72973ef.

@yuexihuanchen

Copy link
Copy Markdown
Author

Thanks for catching this. I changed the check to s == null and added a regression test with null beside the literal string 'null'. The new test failed before the change and now passes. I also manually verified both default quoting and quote: ''; the focused suite now has 14 passing tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with undefined value in empty column when exporting multiple tables in a single csv file

3 participants