Postgresql string parsing
Hi Folks,
I'm looking for the fatest way to parse string in a postgresql function and insert each parsed chunk in a table. Something like that:
CREATE FUNCTION parse_and_insert(text) RETURNS integer AS '
DECLARE
my_string ALIAS FOR $1;
-- empty string, do nothing
IF my_string IS NULL THEN
-- split my_string at each new line char '\n', '\r\n' or '\r'
-- loop for each founded chunk, and simply insert it
INSERT INTO tableX (data) VALUES (chunk);
return 1;
END IF;
-- empty string, do nothing
return 0;
END;
' LANGUAGE 'plpgsql';
My be there is exists complety different and fasted method?
Thanks in advance guys
/Youn
ycrux@club-internet.fr wrote:
Hi Folks,
I'm looking for the fatest way to parse string in a postgresql function and insert each parsed chunk in a table. Something like that:
You might be able to use the |string_to_array function which |splits a
string into array elements using the provided delimiter which could be a
EOL marker.
Then use a loop to iterate through the array and insert into your
table.
Just a quick idea :-)
||
--
Tony Caduto
AM Software Design
http://www.amsoftwaredesign.com
Home of PG Lightning Admin for Postgresql
Your best bet for Postgresql Administration
On Mar 29, 2006, at 12:19 PM, Tony Caduto wrote:
ycrux@club-internet.fr wrote:
Hi Folks,
I'm looking for the fatest way to parse string in a postgresql
function and insert each parsed chunk in a table. Something like
that:You might be able to use the |string_to_array function which |
splits a string into array elements using the provided delimiter
which could be a EOL marker.
Then use a loop to iterate through the array and insert into
your table.
Using a language other than plpgsql might also be a good idea. Perl,
for example.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461