Search code examples
phppostgresqlltree

Undefined function: 7 ERROR: operator does not exist: public.ltree public.< public.ltree[]


I have a problem in PHP when I use ltree from PostgreSQL. I do this in SQL:

SELECT * FROM tabla t
WHERE t.parent_path <@ (
    select array_agg(t1.parent_path)
    from tabla t1
    where t1.id in (1000035, 1000045, 1000055, 1000065)
)

I run the query in phpmyadmin and it works fine, but when I copy and paste, in PHP it does not work. I did a little research and I found that in PHP I need to replace the "<@" and "@>" for "OPERATOR(public.<)" and "OPERATOR(public.>)" respectively.

I test it in php with simple ltree query like:

$sql = "SELECT * FROM tabla t
        WHERE t.parent_path OPERATOR(public.<) (
            select t1.parent_path
            from tabla t1
            where t1.id in = 1000035
        )";
$conn = Zend_Registry::get('conexion');
$respdata = $conn->execute($sql);
return $respdata->fetchAll(PDO::FETCH_ASSOC);

and it works fine, but the thing is that in the real query that I want to execute I have in the left side an ltree an in the other side an ltree[], and when I use "OPERATOR(public.<)" it gives me this error:

"Undefined function: 7 ERROR: operator does not exist: public.ltree public.< public.ltree[]"

This is what I´m trying to do...

$sql = "SELECT * FROM tabla t
        WHERE t.parent_path OPERATOR(public.<) (
            select array_agg(t1.parent_path)
            from tabla t1
               WHERE t1.id IN (1000035, 1000045, 1000055, 1000065)
        )";
$conn = Zend_Registry::get('conexion');
$respdata = $conn->execute($sql);
return $respdata->fetchAll(PDO::FETCH_ASSOC);

Any advise.... tks. Sorry if my English is not good.


Solution

  • Well, thaks to IMSoP i found the answer.

    Change the

    OPERATOR(public.<) 
    

    for

    OPERATOR(public.<@)
    

    Tks a lot.