citusdata / citusdata/citus

non-IMMUTABLE functions are not allowed in CASE or COALESCE statements

Open
#1,313 7 comments 0 reactions 0 assignees View on GitHub
sql
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

Executing this SQL gives an error on a sharded database (table is distributed on root_id):

```
UPDATE sample_table set amount = 50
WHERE id = '2a10f3d8-e492-4582-9d35-f731e91fc937'
and root_id = 1
AND now() between coalesce(start_date, '1-1-1900') and coalesce(end_date, now() + interval '1' day)
```

```
ERROR: non-IMMUTABLE functions are not allowed in CASE or COALESCE statements
```

If I run this on a plain old PSQL instance, it executes just fine.
There's probably better ways to determine if now is between start and end (or if they're null), of course. Though it does seem like a common pattern.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.