Expression rationnelle dans SELECT
Bonjour,
J'ai essayé ceci (pris sur le site de la doc postgresql) :
Code:
SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', E'\\s+');
Message d'erreur :
le type «e» n'existe pas.
J'essaie avec :
Code:
SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', '\\s+');
Message d'erreur :
la fonction regexp_split_to_array("unknown", "unknown") n'existe pas
Je modifie :
Code:
SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog'::char, '\\s+');
Message d'erreur :
la fonction regexp_split_to_array(character, "unknown") n'existe pas HINT: Aucune fonction ne correspond au nom donné et aux types d'arguments. Vous devez ajouter des conversions explicites de type.explicit type casts
Quelle est la bonne syntaxe ?
@senacle :: string_to_table
Salut,
si tu as accès à la fonction string_to_array alors pour string_to_table, tu peux t'inspirer de ce premier jet :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| CREATE OR REPLACE FUNCTION string_to_table(blabla text, separator text)
RETURNS SETOF text as $$
DECLARE
string_arr text[];
r int;
res text;
BEGIN
string_arr := string_to_array(blabla,separator);
FOR r in 1..array_upper(string_arr,1) LOOP
RETURN NEXT string_arr[r];
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
--utilisation
drop table if exists ma_table cascade;
create table ma_table as
select * from string_to_table('the quick brown fox jumped over the lazy dog', ' '); |