Skip to content

[#121] Handle null rows in triggers#128

Merged
maltoe merged 1 commit intomainfrom
fix/issue-121-handle-null-rows-in-records
Jan 28, 2025
Merged

[#121] Handle null rows in triggers#128
maltoe merged 1 commit intomainfrom
fix/issue-121-handle-null-rows-in-records

Conversation

@maltoe
Copy link
Collaborator

@maltoe maltoe commented Jan 28, 2025

When the trigger query returns null, we currently fail with a rather obscure

** (Postgrex.Error) ERROR 23502 (not_null_violation) null value in column "data" of relation "changes" violates not-null constraint

         table: changes
         column: data

That is because Postgres propagates the null value when the second argument to the - (jsonb, text[]) operator is null`.

-- returns null
select '{}'::jsonb - NULL;

This patch handles this case explicitly and raises a better error message.

Fixes #121

@maltoe maltoe force-pushed the fix/issue-121-handle-null-rows-in-records branch from 8c3e071 to 8283ae1 Compare January 28, 2025 07:29
When the trigger query returns null, we currently fail with a rather
obscure

```
** (Postgrex.Error) ERROR 23502 (not_null_violation) null value in column "data" of relation "changes" violates not-null constraint

         table: changes
         column: data
```

That is because Postgres propagates the null value when the second
argument to the `- (jsonb, text[])` operator is null`.

```
-- returns null
select '{}'::jsonb - NULL;
```

This patch handles this case explicitly and raises a better error
message.
@maltoe maltoe force-pushed the fix/issue-121-handle-null-rows-in-records branch from 8283ae1 to a5243b0 Compare January 28, 2025 07:46
@maltoe maltoe merged commit 0df3c10 into main Jan 28, 2025
10 checks passed
@maltoe maltoe deleted the fix/issue-121-handle-null-rows-in-records branch January 28, 2025 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

null value in column "data" of relation "changes" violates not-null constraint

1 participant