lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.ophir.dev
MIT License
878 stars 62 forks source link

postgres custom operators are not parsed correctly #372

Open amrutadotorg opened 4 weeks ago

amrutadotorg commented 4 weeks ago

Hi, is it possible to add support for PGroonga operators?

Here is the list of operators: https://pgroonga.github.io/reference/

&@ operator: Full text search by a keyword
&@~ operator: Full text search by easy to use query language
&@* operator: Similar search
&` operator: Advanced search by ECMAScript like query language
&@| operator: Full text search by an array of keywords
&@~| operator: Full text search by an array of queries in easy to use query language

Currently, it seems like it does not work, or I might be doing something wrong. Thank you.

SELECT 
    'list' AS component,
    'headline' AS id,
    'No posts found' as empty_title,
    'No posts found' as empty_description_md;

SELECT 
    post.id,
    pgroonga_highlight_html(post.content,pgroonga_query_extract_keywords($search)) AS description_md,
    translations.language_code
FROM 
    post
JOIN 
    translations ON translations.element_id = post.id
    AND translations.element_type = 'post_post'
    AND translations.language_code = 'en'
WHERE 
    post.content &@~ $search
LIMIT 5;
2024-06-03 05:02:19.187 CEST [10443] ERROR:  operator does not exist: @~ text at character 320
2024-06-03 05:02:19.187 CEST [10443] HINT:  No operator matches the given name and argument type. You might need to add an explicit type cast.
2024-06-03 05:02:19.187 CEST [10443] STATEMENT:  SELECT post.id, pgroonga_highlight_html(post.content, pgroonga_query_extract_keywords(CAST($1 AS TEXT))) AS description_md, translations.language_code FROM post JOIN translations ON translations.element_id = post.id AND translations.element_type = 'post_post' AND translations.language_code = 'en' WHERE post.content & @~CAST($2 AS TEXT) LIMIT 5;
test=# select count(*)
FROM
    post
JOIN
    translations ON translations.element_id = post.id
    AND translations.element_type = 'post_post'
WHERE
    post.content &@~ 'myślę'
LIMIT 5;
 count
-------
    16
(1 row)
amrutadotorg commented 3 weeks ago

temporary solution

CREATE OR REPLACE FUNCTION my_pgroonga_match(content TEXT, query TEXT)
RETURNS BOOLEAN AS $$
SELECT $1 &@~ $2;
$$ LANGUAGE sql IMMUTABLE;
lovasoa commented 3 weeks ago

I opened a pull request upstream https://github.com/sqlparser-rs/sqlparser-rs/pull/1302

Now waiting for it to be merged

lovasoa commented 3 weeks ago

The patch was merged upstream, this will be fixed when sqlparser releases their next version and we include it.