fix(csv-to-pg): emit empty array '{}' instead of NULL for array types#887
Merged
pyramation merged 3 commits intomainfrom Mar 24, 2026
Merged
Conversation
When array-typed columns (jsonb[], uuid[], text[]) have null or empty
values, emit '{}' (empty PostgreSQL array literal) instead of SQL NULL.
This fixes NOT NULL constraint violations when exported SQL is deployed
to databases where array columns have NOT NULL defaults.
Changes:
- parse.ts: makeNullOrThrow emits '{}' for array types instead of NULL
- parse.ts: psqlArray returns '{}' for empty arrays instead of undefined
- export-meta.ts: COALESCE fields/grant_privileges in secure_table_provision query
- Added tests for null and empty array serialization
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Resolve conflict in pgpm/export/src/export-utils.ts (take main's version). Apply COALESCE fix to new pgpm/export/src/export-meta.ts location.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When array-typed columns (
jsonb[],uuid[],text[]) have null or empty values,csv-to-pgnow emits'{}'(empty PostgreSQL array literal) instead of SQLNULL. This fixes NOT NULL constraint violations when exported SQL is deployed to databases where array columns have NOT NULL defaults (e.g.secure_table_provision.fieldsandsecure_table_provision.grant_privileges).csv-to-pg/src/parse.ts:makeNullOrThrownow returns'{}'for any array type instead ofNULLwhen the value is missing/empty.psqlArrayalso returns'{}'for empty arrays instead ofundefined. A newisArrayTypehelper detects array types by checking for trailing[].Two new test cases verify null and empty array inputs both emit
'{}'instead ofNULL.Updates since last revision
COALESCEfix frompgpm/export/src/export-meta.ts— the csv-to-pg serialization layer now handles this, so the query-level workaround is unnecessary.Review & Testing Checklist for Human
makeNullOrThrow: This changes behavior for ALL array types across ALL consumers ofcsv-to-pg, not just the export pipeline. Verify no existing consumer relies on getting SQLNULLfor empty/missing array columns. If any table legitimately needs NULL arrays, this would silently change the semantics.NULL → '{}'post-processing workaround.Notes
psqlArraychange (empty array →'{}'instead ofundefined) also affects thetext[]handler path, which callspsqlArraydirectly before checking emptiness.pgpm-deployfailed withnull value in column "fields" violates not-null constraint.Link to Devin session: https://app.devin.ai/sessions/f72c3360c9494043aa60d59ff302be83
Requested by: @pyramation