Segfault-Inc / Multicorn

Data Access Library
https://multicorn.org/
PostgreSQL License
699 stars 145 forks source link

module only gets qual when it's a constant string, qual lost when the result of an expression #189

Open max-l opened 7 years ago

max-l commented 7 years ago

I have a multicorn module that starts with this code :

def execute(self, quals, columns):
    path = None
    for qual in quals:
        if qual.field_name == "path":
            path = qual.value
    if path == None:
        log_to_postgres("must have non null path in where clause", ERROR)

It must have a "path" qual in a where clause, or join condition

This query works :

SELECT l.*
from altorf_logs_ms l 
WHERE
  l.path = '/netmount/130529_17_OT3_YY1_1_HEK293/logs'
;

However, this one does not, the code above falls in the "if path == None" case, i.e. the "path" qual gets lost when it is not a constant string

with q0 as (SELECT '/netmount/130529_17_OT3_YY1_1_HEK293/logs'::text p)
SELECT l.*
from altorf_logs_ms l 
join q0 on l.path = q0.p

Logically the two queries are the same, but something doesn't work in the second