Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined function: 7 ERROR: function to_tsvector(unknown, tsvector) does not exist #54908

Open
DumboJetEngine opened this issue Mar 5, 2025 · 0 comments

Comments

@DumboJetEngine
Copy link

DumboJetEngine commented Mar 5, 2025

Laravel Version

11.44.0

PHP Version

8.3.15

Database Driver & Version

PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

Description

I have added FTS functionality in my application like so:

Schema::table('table', function (Blueprint $table) {
    //$table->fullText(['title'], 'messages_title_fulltext')->language('greek'); // <--- With this I had issues with ignoring greek diacritics...
    DB::statement("ALTER TABLE table ADD COLUMN title_fts tsvector GENERATED ALWAYS AS (to_tsvector('greek', coalesce(title,''))) STORED;");
});

Searching:

$builder = Table::orderByDesc('created_at')->orderByDesc('id');
$builder->whereFullText('title_fts', $title);

When executing the whereFullText(), I get an error of:

Undefined function: 7 ERROR: function to_tsvector(unknown, tsvector) does not exist

Doing something like this, solves the problem, but opens me up to SQL injection attacks:

$builder->whereRaw("title_fts @@ to_tsquery('greek', '$title:*')");

And I have also tried this, which didn't work:

$builder->whereRaw("title_fts @@ to_tsquery('greek', '?:*')", [$title]);

PDOException: SQLSTATE[08P01]: <>: 7 ERROR: bind message supplies 1 parameters, but prepared statement "pdo_stmt_00000003" requires 0

Am I doing something wrong, or this is a bug?

UPDATE:
I have found a workaround with this code, but it is possible to avoid using whereRaw() altogether, it would be nice to know:

$builder->whereRaw("title_fts @@ to_tsquery('greek', ?)", ["$title:*"])

Steps To Reproduce

Create a table with a title column and add FTS to it, using the partial migration code given above.
Try to search with the provided code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant