Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite LIMIT 0 does not work as expected with COALESCE(), use WHERE FALSE instead #20

Closed
AnyhowStep opened this issue Nov 8, 2019 · 2 comments
Assignees
Labels
bug Something isn't working meta Not particularly actionable, but describes a large class of problems sqlite

Comments

@AnyhowStep
Copy link
Owner

This is a copy-paste from the README


Investigate Bug with SQLite,

CREATE TABLE "myTable" (
	"myColumn" INT PRIMARY KEY
);
INSERT INTO
	"myTable"("myColumn")
VALUES
	(4);

SELECT (
  3e0 IN(
    COALESCE(
      (
        SELECT
          "myTable"."myColumn" AS "myTable--myColumn"
        FROM
          "myTable"
        LIMIT
          0
        OFFSET
          0
      ),
      3e0
    )
  )
);

Investigate Bug with SQLite,

CREATE TABLE "myTable" (
  "myColumn" INT PRIMARY KEY
);
INSERT INTO
  "myTable"("myColumn")
VALUES
  (4);

SELECT
  COALESCE(
    (
      SELECT
        "myTable"."myColumn" AS "myTable--myColumn"
      FROM
        "myTable"
      LIMIT
        0
      OFFSET
        0
    ),
    3e0
  );
  • Expected result : 3
  • PostgreSQL : 3
  • MySQL : 3
  • SQLite : 4
    • COALESCE() seems to ignore the LIMIT 0 clause.
    • Use WHERE FALSE when building SQL string.
CREATE TABLE "myTable" (
  "myColumn" INT PRIMARY KEY
);
INSERT INTO
  "myTable"("myColumn")
VALUES
  (4);

SELECT
  COALESCE(
    (
      SELECT
        "myTable"."myColumn" AS "myTable--myColumn"
      FROM
        "myTable"
      WHERE
        FALSE
      LIMIT
        0
      OFFSET
        0
    ),
    3e0
  );

This isn't related to this library directly, because it's a problem with SQLite.
But it's something to look out for.

@AnyhowStep AnyhowStep added bug Something isn't working meta Not particularly actionable, but describes a large class of problems labels Nov 8, 2019
@AnyhowStep AnyhowStep self-assigned this Nov 8, 2019
@AnyhowStep AnyhowStep changed the title SQLite LIMIT 0 does not work as expected, use WHERE FALSE instead SQLite LIMIT 0 does not work as expected with COALESCE(), use WHERE FALSE instead Nov 8, 2019
@AnyhowStep
Copy link
Owner Author

Holy fuck. They fixed it.
https://sqlite.org/src/info/82e5dcf5c1d500ed

I reported this on 2019-09-22.
They fixed it on 2019-09-23.

And I only just realized it... Today. 2020-03-11.

I just tested it on SQLite 3.31 and it has, indeed, been fixed!

@AnyhowStep
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working meta Not particularly actionable, but describes a large class of problems sqlite
Projects
None yet
Development

No branches or pull requests

1 participant