0
J'ai besoin de bulid une procédure stockée qui prend en entrée un tableau de varchars. Il recherchera ces syntaxe en utilisant commerequête de recherche de texte biulding dans postgres
SELECT *
FROM mytable
WHERE search_index @@ to_tsquery(' ');
Si je donne l'entrée à la procédure comme Tom, Dick, harry la requête doit être construite dynamiquement comme
SELECT *
FROM mytable
WHERE search_index @@ to_tsquery('tom | dick | harry ');
CREATE OR REPLACE FUNCTION text_search(search_terms character varying[], ent_id bigint)
RETURNS entity_base AS
$BODY$DECLARE
result_data entity_base;
search_data text;
BEGIN
search_data := array_to_string('search_terms[]', '|');
SELECT * INTO result_data FROM entity_base WHERE search_index @@ to_tsquery(search_data) and entity_id = ent_id;
RETURN result_data;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
Quand je lance cette im obtenir erreur
ERROR: could not determine polymorphic type because input has type "unknown"
CONTEXT: SQL statement "SELECT array_to_string('search_terms[]', '|')"
PL/pgSQL function "text_search" line 5 at assignment
********** Error **********
ERROR: could not determine polymorphic type because input has type "unknown"
SQL state: 42804
Context: SQL statement "SELECT array_to_string('search_terms[]', '|')"
PL/pgSQL function "text_search" line 5 at assignment
Utilisez array_to_string (search_terms, '|'), sans guillemets car ce n'est pas une chaîne, c'est une variable. –