PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 6th, 2012, 08:37 AM
storm_Bringer storm_Bringer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 2 storm_Bringer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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! :)))

Reply With Quote
  #2  
Old August 8th, 2012, 11:06 AM
jehsom jehsom is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 9 jehsom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 53 sec
Reputation Power: 0
Your friend's solution seems perfectly valid and simple. Just throw it into a plpgsql function...

Reply With Quote
  #3  
Old August 8th, 2012, 11:37 AM
storm_Bringer storm_Bringer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 2 storm_Bringer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 52 sec
Reputation Power: 0
yeah thanks! in the end i've just wrote pl/pgsql function based on his suggestion...just wondered probably there is some another way, that doesn't use regex functions....
st_bringer

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Pl/pgsql function to count number of same words in two strings

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap