SQLite Greatest implementation is wrong for parameters with the value NULL

Created on 16 October 2012, over 12 years ago
Updated 23 August 2023, over 1 year ago

Problem/Motivation

While exploring πŸ› SQLite exception "primary key must be unique" when sequences table erroneously contains more than one row Postponed: needs info , chx and I almost "fixed" the implemenation of "greatest" in SQLite driver, because the code is misleading.

Here, instead is a patch (was #9 in the other issue, but turned out to be unrelated) that simplifies the function and adds a comment to make its desired behavior clear. This behavior is that we mimic the way that the greatest function in MySQL works. If the function is called with less then two parameters a exception is called. With two or more parameters and with one or more of those parameters being NULL will return the value NULL.

The problem is that PostgreSQL works a little bit different. And there is no way we can change this. Calling greatest with one parameter just returns the parameter. With two or more parameters will only return NULL if ALL the parameters are NULL.

Steps to reproduce

Proposed resolution

Change sqlFunctionGreatest() to not fail when an argument in NULL. And mimic MySQL as explained above.

Remaining tasks

Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
SQLite driverΒ  β†’

Last updated 27 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States lotyrin

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024