![]() (Note, I'm not sure if you really wanted that column named "Column", requiring identifier quoting to avoid keyword clash, but, there you are. Obviously you can extend this to handle a delimiter of your choosing, etc. Is there a way to use an input array of values as a way to replace different string occurrences in one go Say we have an input array of 'a', 'b', 'c', 'd', and a replacement array of '1', '2', '3', '4'. Using regexpreplace(('def4abcdef4ab','4', '','g') i can replace/erase all occurrences of '4', but i want to also replace all occurences of 'e' and b' in the same process, without using several nested. Pg=> SELECT "Column" FROM psplit_to_rows('how now brown cow') d("Column") Hi i would like to use regexpreplace (or any other postgres function if reasonable) to replace characters in a string by a '', i.e. oldtext is the text that you want to search and replace. Pg=> CREATE FUNCTION psplit_to_rows(text) RETURNS SETOF TEXT AS $$ The following illustrates the syntax of the PostgreSQL REPLACE () function: REPLACE ( source, oldtext, newtext ) Code language: SQL (Structured Query Language) (sql) The REPLACE () function accepts three arguments: source is a string where you want to replace. Original answer: using PL/perl: pg=> CREATE LANGUAGE plperl ![]() Pg=> SELECT "Column" FROM string_to_rows('how now brown cow') d("Column") Updated answer: using PL/pgSQL: pg=> CREATE OR REPLACE FUNCTION string_to_rows(text) RETURNS SETOF TEXT AS $$įOR i IN array_lower(elems, 1).
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |