Opened 6 years ago

Closed 6 years ago

#29710 closed New feature (wontfix)

Support simple-style CASE expressions

Reported by: Tom Forbes Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Mariusz Felisiak Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently we only support one variant of the SQL CASE statement:

CASE WHEN a = 1 THEN 'one' WHEN a = 2 THEN 'two' ELSE '?' END

There is a simpler version when you just need to do an exact check on a single value:

CASE a WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE '?' END

This may be easier for databases to optimize against, especially if you are producing large statements with many cases (https://code.djangoproject.com/ticket/23646)

Change History (4)

comment:1 by Tom Forbes, 6 years ago

I did some benchmarking on MySQL and Postgres, and it seems the difference between the two is negligible. This might not hold for all databases however the work to add this might not be worth it.

comment:2 by Mariusz Felisiak, 6 years ago

Type: UncategorizedNew feature

IMO it will not have a performance impact also on Oracle, that's why I don't think it is worth adding this to the Django. Thanks for checking this.

comment:3 by Mariusz Felisiak, 6 years ago

Cc: Mariusz Felisiak added

comment:4 by Claude Paroz, 6 years ago

Resolution: wontfix
Status: newclosed

Let's close, until more compelling arguments are provided to implement this.

Note: See TracTickets for help on using tickets.
Back to Top