
August 6th, 2012, 08:37 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 2
Time spent in forums: 10 m 52 sec
Reputation Power: 0
|
|
|
Pl/pgsql function to count number of same words in two strings
hello forum! could please anyone help me to write a pl/pgsql function to count number of same words in two given strings?
I've given up here:
CREATE OR REPLACE FUNCTION word_match (
1ststr text, 2ndstr text
) RETURNS integer AS $$
BEGIN
a=string_2_array(1ststr, ' ')
b=2ndstr
n=1
FOR n<array_upper(a) LOOP
a[n] ilike '%||b||%'
Than my friend told me that probably it is better to do it through regex like this:
select count(*) from regexp_split_to_table( 'string one', ' ') a where a in (select regexp_split_to_table( 'string two', ' '));
but just for the matter of interest could anyone tell how to do it through pl/pgsql?
thanks a lot! :)))
|