PostgreSQL-For-Wordpress / postgresql-for-wordpress

A maintained fork of https://wordpress.org/plugins/postgresql-for-wordpress/
GNU General Public License v2.0
209 stars 68 forks source link

Wrong conversion of a SELECT request #84

Closed hahnn closed 5 months ago

hahnn commented 8 months ago

Hello,

There is a conversion issue about a SELECT request made against the _wpposts SQL table as shown below:

---------------------
[1701095314.7028] Error running :
SELECT p.ID FROM wp_posts p WHERE post_type='scheduled-action' AND p.post_status IN ('pending') AND p.post_modified_gmt <= '2023-11-27 14:23:34' AND p.post_password != '' ORDER BY p.post_date_gmt ASC LIMIT 0, 20
---- converted to ----
SELECT p."ID" , p.post_date_gmt FROM wp_posts p WHERE post_type='scheduled-action' AND p.post_status IN ('pending') AND p.post_modified_gmt <= '2023-11-27 14:23:34' AND p.post_password <> 0 ORDER BY p.post_date_gmt ASC LIMIT 20 OFFSET 0
----> ERREUR:  l'opérateur n'existe pas : character varying <> integer
LINE 1: ..._gmt <= '2023-11-27 14:23:34' AND p.post_password <> 0 ORDER...
                                                             ^
HINT:  Aucun opérateur ne correspond au nom donné et aux types d'arguments.
Vous devez ajouter des conversions explicites de type.
---------------------

In the converted result, a conditionnal test has been wrongly updated from:

p.post_password != ''

to

p.post_password <> 0

There is simply no conversion to make here because the column type of _p.postpassword is varchar and not a numeric one, so it should remain as it is.

mattbucci commented 6 months ago

This code dates back 15 years :)

https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress/blame/f2a05dddbeec902ec5a095b1e0698accf89d832d/pg4wp/driver_pgsql.php#L337 image