Обсуждение: PLPerl Trigger to update text search

Поиск
Список
Период
Сортировка

PLPerl Trigger to update text search

От
Alex Magnum
Дата:
Hi,

I am trying to update a tsvector field through a plperl trigger.

$_TD->{new}{text_search} = to_tsvector('pg_catalog.english', 'text1 text2');

but plperl does not seem to like that... 
ERROR:  Undefined subroutine &main::to_tsvector called 

anyone done that and could help me out if that is actually possible?

Thanks in advance
Alex

Re: PLPerl Trigger to update text search

От
Alex Hunsaker
Дата:


On Fri, Jul 31, 2015 at 6:07 AM, Alex Magnum <magnum11200@gmail.com> wrote:
Hi,

I am trying to update a tsvector field through a plperl trigger.

$_TD->{new}{text_search} = to_tsvector('pg_catalog.english', 'text1 text2');


You need to wrap that into an actual SPI call at the very least. Database procedures are not available natively for PL languages in general (minus perhaps pl/pgsql).

 Something like:

$_TD->{new}{text_search} = spi_exec_query("to_tsvector('pg_catalog.english', ". quote_literal('text1 text2') .";")->{rows}[0]{to_tsvector};

If performance is any consideration, I suspect pl/pgsql would be the clear winner.

Re: PLPerl Trigger to update text search

От
Alex Hunsaker
Дата:


On Fri, Jul 31, 2015 at 7:15 PM, Alex Hunsaker <badalex@gmail.com> wrote:



$_TD->{new}{text_search} = spi_exec_query("to_tsvector('pg_catalog.english', ". quote_literal('text1 text2') .";")->{rows}[0]{to_tsvector};


Err that should be:
(still untested, was missing the "select" bit)

$_TD->{new}{text_search} = spi_exec_query("select to_tsvector('pg_catalog.english', ". quote_literal('text1 text2') .";")->{rows}[0]{to_tsvector};