Esqueleto-Bug: Umformung boolscher Formel geht nicht, obwohl kein NULL involviert ist #155

Open
opened 2024-02-07 10:19:09 +01:00 by jost · 4 comments
jost commented 2024-02-07 10:19:09 +01:00 (Migrated from gitlab.uniworx.de)

Warum liefert

E.where_ $ E.not_ (ilog E.^. InterfaceLogInterface E.==. E.val "LMS" E.&&. ilog E.^. InterfaceLogSubtype E.==. E.val "F")

nicht das gleiche Ergebnis wie

E.where_ $ ilog E.^. InterfaceLogInterface E.!=. E.val "LMS" E.||. ilog E.^. InterfaceLogSubtype E.!=. E.val "F",

obwohl keine NULL-Werte involviert sind?

Während es in Esqueleto nicht funktioniert, klappt es direkt in SQL problemlos, siehe unten. Die erste Abfrage liefert nur die Zeile mit interface="Printer" und subtype="F". Die zweite Abfrage funktioniert wie erwartet und liefert das gleiche Ergebnis wir die SQL-Abfrage:

uniworx=# SELECT * FROM "interface_log" ORDER BY 2,3,4,1;

id interface subtype write time rows info success
1 AVS Synch t 2024-02-07 09:58:59.956492+01 27749 t
47 LMS F f 2024-02-07 09:54:45.941814+01 219 t
16 LMS F-deq t 2024-02-07 09:51:32.321986+01 25 8 expired t
14 LMS F-enq t 2024-02-07 09:51:31.684825+01 14 t
15 LMS R-deq t 2024-02-07 09:51:32.285071+01 0 0 expired t
13 LMS R-enq t 2024-02-07 09:51:31.646956+01 0 t
2 Printer Acknowledge t 2024-02-07 09:58:59.961534+01 t
17 Printer F t 2024-02-07 09:52:02.913911+01 1 Print command ignored due to setting 'mail-reroute-to' being set. t

uniworx=# SELECT * FROM "interface_log" WHERE NOT(interface = 'LMS' AND subtype = 'F') ORDER BY 2,3,4,1;

id interface subtype write time rows info success
1 AVS Synch t 2024-02-07 09:58:59.956492+01 27749 t
16 LMS F-deq t 2024-02-07 09:51:32.321986+01 25 8 expired t
14 LMS F-enq t 2024-02-07 09:51:31.684825+01 14 t
15 LMS R-deq t 2024-02-07 09:51:32.285071+01 0 0 expired t
13 LMS R-enq t 2024-02-07 09:51:31.646956+01 0 t
2 Printer Acknowledge t 2024-02-07 09:58:59.961534+01 t
17 Printer F t 2024-02-07 09:52:02.913911+01 1 Print command ignored due to setting 'mail-reroute-to' being set. t

uniworx=# SELECT * FROM "interface_log" WHERE (interface <> 'LMS' OR subtype <> 'F') ORDER BY 2,3,4,1;

id interface subtype write time rows info success
1 AVS Synch t 2024-02-07 09:58:59.956492+01 27749 t
16 LMS F-deq t 2024-02-07 09:51:32.321986+01 25 8 expired t
14 LMS F-enq t 2024-02-07 09:51:31.684825+01 14 t
15 LMS R-deq t 2024-02-07 09:51:32.285071+01 0 0 expired t
13 LMS R-enq t 2024-02-07 09:51:31.646956+01 0 t
2 Printer Acknowledge t 2024-02-07 09:58:59.961534+01 t
17 Printer F t 2024-02-07 09:52:02.913911+01 1 Print command ignored due to setting 'mail-reroute-to' being set. t
Warum liefert `E.where_ $ E.not_ (ilog E.^. InterfaceLogInterface E.==. E.val "LMS" E.&&. ilog E.^. InterfaceLogSubtype E.==. E.val "F")` nicht das gleiche Ergebnis wie `E.where_ $ ilog E.^. InterfaceLogInterface E.!=. E.val "LMS" E.||. ilog E.^. InterfaceLogSubtype E.!=. E.val "F"`, obwohl keine `NULL`-Werte involviert sind? Während es in Esqueleto nicht funktioniert, klappt es direkt in SQL problemlos, siehe unten. Die erste Abfrage liefert nur die Zeile mit `interface="Printer"` und `subtype="F"`. Die zweite Abfrage funktioniert wie erwartet und liefert das gleiche Ergebnis wir die SQL-Abfrage: `uniworx=# SELECT * FROM "interface_log" ORDER BY 2,3,4,1;` | id | interface | subtype | write | time | rows | info | success | | -- | ---------- | ---------- | ----- | ----------------------------- | ------ | ---------------------------------------------------------------- | --------- | | 1 | AVS | Synch | t | 2024-02-07 09:58:59.956492+01 | 27749 | | t | | 47 | LMS | F | f | 2024-02-07 09:54:45.941814+01 | 219 | | t | | 16 | LMS | F-deq | t | 2024-02-07 09:51:32.321986+01 | 25 | 8 expired | t | | 14 | LMS | F-enq | t | 2024-02-07 09:51:31.684825+01 | 14 | | t | | 15 | LMS | R-deq | t | 2024-02-07 09:51:32.285071+01 | 0 | 0 expired | t | | 13 | LMS | R-enq | t | 2024-02-07 09:51:31.646956+01 | 0 | | t | | 2 | Printer | Acknowledge | t | 2024-02-07 09:58:59.961534+01 | | | t | | 17 | Printer | F | t | 2024-02-07 09:52:02.913911+01 | 1 | Print command ignored due to setting 'mail-reroute-to' being set. | t | `uniworx=# SELECT * FROM "interface_log" WHERE NOT(interface = 'LMS' AND subtype = 'F') ORDER BY 2,3,4,1;` id | interface | subtype | write | time | rows | info | success ----|-----------|-------------|-------|-------------------------------|-------|-------------------------------------------------------------------|--------- 1 | AVS | Synch | t | 2024-02-07 09:58:59.956492+01 | 27749 | | t 16 | LMS | F-deq | t | 2024-02-07 09:51:32.321986+01 | 25 | 8 expired | t 14 | LMS | F-enq | t | 2024-02-07 09:51:31.684825+01 | 14 | | t 15 | LMS | R-deq | t | 2024-02-07 09:51:32.285071+01 | 0 | 0 expired | t 13 | LMS | R-enq | t | 2024-02-07 09:51:31.646956+01 | 0 | | t 2 | Printer | Acknowledge | t | 2024-02-07 09:58:59.961534+01 | | | t 17 | Printer | F | t | 2024-02-07 09:52:02.913911+01 | 1 | Print command ignored due to setting 'mail-reroute-to' being set. | t `uniworx=# SELECT * FROM "interface_log" WHERE (interface <> 'LMS' OR subtype <> 'F') ORDER BY 2,3,4,1;` id | interface | subtype | write | time | rows | info | success ----|-----------|-------------|-------|-------------------------------|-------|-------------------------------------------------------------------|--------- 1 | AVS | Synch | t | 2024-02-07 09:58:59.956492+01 | 27749 | | t 16 | LMS | F-deq | t | 2024-02-07 09:51:32.321986+01 | 25 | 8 expired | t 14 | LMS | F-enq | t | 2024-02-07 09:51:31.684825+01 | 14 | | t 15 | LMS | R-deq | t | 2024-02-07 09:51:32.285071+01 | 0 | 0 expired | t 13 | LMS | R-enq | t | 2024-02-07 09:51:31.646956+01 | 0 | | t 2 | Printer | Acknowledge | t | 2024-02-07 09:58:59.961534+01 | | | t 17 | Printer | F | t | 2024-02-07 09:52:02.913911+01 | 1 | Print command ignored due to setting 'mail-reroute-to' being set. | t
jost commented 2024-02-07 10:20:41 +01:00 (Migrated from gitlab.uniworx.de)

mentioned in issue #2

mentioned in issue #2
jost commented 2024-02-07 10:39:28 +01:00 (Migrated from gitlab.uniworx.de)

mentioned in commit 618c78a69d

mentioned in commit 618c78a69d7db77a745282c63356a936facff70d
jost commented 2024-02-12 11:17:02 +01:00 (Migrated from gitlab.uniworx.de)

Mit LOGLEVEL=debug npm run start 2> debug.log zeigte sich, dass unsere Esqueleto Version einfach falsch klammert:

Der Code

E.where_ $ E.not_ (ilog E.^. InterfaceLogInterface E.==. E.val "LMS" E.&&.  ilog E.^. InterfaceLogSubtype E.==. E.val (sanitize "F"))

wird in der Anfrage zu

WHERE NOT ("interface_log"."interface" = 'LMS') AND ("interface_log"."subtype" = 'F')

Mit Verwendung der Funktion Database.Esqueleto.Utils.parens funktioniert es aber korrekt.

parens :: E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value a)
parens = E.unsafeSqlFunction ""
Mit `LOGLEVEL=debug npm run start 2> debug.log` zeigte sich, dass unsere Esqueleto Version einfach falsch klammert: Der Code ``` E.where_ $ E.not_ (ilog E.^. InterfaceLogInterface E.==. E.val "LMS" E.&&. ilog E.^. InterfaceLogSubtype E.==. E.val (sanitize "F")) ``` wird in der Anfrage zu ``` WHERE NOT ("interface_log"."interface" = 'LMS') AND ("interface_log"."subtype" = 'F') ``` Mit Verwendung der Funktion `Database.Esqueleto.Utils.parens` funktioniert es aber korrekt. ``` parens :: E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value a) parens = E.unsafeSqlFunction "" ```
jost commented 2024-02-12 11:31:03 +01:00 (Migrated from gitlab.uniworx.de)

mentioned in commit e2be8bbd5c

mentioned in commit e2be8bbd5c82fd8a68187ee6bea4ab49e2980797
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: fraport/fradrive-old#155
No description provided.