473,799 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regular expression searches

I am trying to create a PL/PGSQL function that can parse a street address
into the component parts (i.e. "200 W 54th Street" into num->200 dir->W
street->54th type->ST).

What I would like is to be able to use regular expressions within PL/PGSQL
to accomplish this using mapping tables for the different components.

For example, I would have a table with all the different acceptible road
types:
Abbreviation | Regex
_______________ _______________ ____
RD | R(OA)?D
AV | AVE?(NUE)?
ST | STR?(EET)?

and replace everything that matches the regex with the abbreviation while
saving the road type as a variable.

Any help would be appreciated.

Thanks,
David


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #1
4 3143
On Thu, Oct 07, 2004 at 04:07:08PM -0500, David Bitner wrote:
I am trying to create a PL/PGSQL function that can parse a street address
into the component parts (i.e. "200 W 54th Street" into num->200 dir->W
street->54th type->ST).

What I would like is to be able to use regular expressions within PL/PGSQL
to accomplish this using mapping tables for the different components.


Perhaps PL/Perl or PL/Python would be more appropriate for this.

Cheers,
D
--
David Fetter da***@fetter.or g http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2

Hello All

I used to be MySQL user. I recently changed to PostGres. It is much more
fun. I have two questions. First, is it possible to call other functions
from plpython functions? I used following but didn't work. Any comments?

CREATE OR REPLACE FUNCTION test4()
RETURNS "varchar" AS
'
return plpy.execute("s elect getcountrycode( "9821788")" ,1)
'
LANGUAGE 'plpythonu' VOLATILE;
Also, do you know any better way (apart from psql) to enter and test
functions? I used pgAdmin, but it didn't work properly with plpython. I
guess the indentation is not right and everytime I have to create the
function from psql in order to work. A little bit strange but it happened! I
don't know if I am doing something wrong or not but it seems no other person
complained.

Thanking you in advance
Regards
kia


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #3
"Kiarash Bodouhi" <kb******@yahoo .com> writes:
I have two questions. First, is it possible to call other functions
from plpython functions? I used following but didn't work. Any comments? CREATE OR REPLACE FUNCTION test4()
RETURNS "varchar" AS
'
return plpy.execute("s elect getcountrycode( "9821788")" ,1)
'
LANGUAGE 'plpythonu' VOLATILE;
Didn't work how, exactly? I don't know much Python but I'd think you
have a quote-nesting mistake there. And anyway, shouldn't it be single
quotes in the SQL command, ie

return plpy.execute("s elect getcountrycode( '9821788')",1)

which you actually need to write as

return plpy.execute("s elect getcountrycode( \'9821788\')",1 )

because you're already inside a single-quoted string.
Also, do you know any better way (apart from psql) to enter and test
functions? I used pgAdmin, but it didn't work properly with plpython.


Dunno; it is certainly possible that pgAdmin isn't careful about
preserving leading indentation. I'd suggest taking that up with the
pgAdmin guys; I'm sure they'll fix it when you point out that python
is picky about this.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #4
On Thu, Oct 07, 2004 at 10:55:03PM -0400, Tom Lane wrote:
return plpy.execute("s elect getcountrycode( \'9821788\')",1 )


plpy.execute() returns a result object; querying a function that
returns a result object will probably look like this:

test=> select test4();
test4
--------------------------------
<PLyResult object at 0x367140>
(1 row)

The code should look more like this:

result = plpy.execute("s elect getcountrycode( \'9821788\')",1 )
return result[0]["getcountrycode "]

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1731
by: MJ | last post by:
I'm having problems coming up with a regular expression that works for what I want. I need to extract a few numbers from from html. Here's a snippet: <tr><td align="right">Consolidated Metro Area (CMSA)</td><td align="left"><strong> SEATTLE-TACOMA-BREMERTON, WA ( 7602 )</td></tr> <tr><td align="right">Primary Metro Area (PMSA)</td><td align="left"><strong>SEATTLE-BELLEVUE-EVERETT, WA ( 7600 )</td></tr>
1
3664
by: Jon Nicoll | last post by:
Hi All I would like to be able to use regular expression searches to determine the index(es) within a string where a match was found. ie., given import re def myFunc(): # to be written ;-)
1
4187
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
4
294
by: Aah | last post by:
Where can I get a good resource to know more about Regular expression in vb.net I have like 1000 asp/aspx files where I need to find certain file path and update it with certain text. I am thinking of creating a win app to do this. Can anyone suggest what will be the best way to do this?
3
1536
by: Gopinath | last post by:
Hi JavaScript Gurus, I've a question on Regular Expressions using RegExp object. I just want to know whether it is possible to do the search (see below) using RegExp. Any pointers would be of immense help. Thanks. My simple JavaScript code (inside a function): ======================= var strList = "~@!~1#Apple~@!~2#Orange~@!~3#Mango~@!~4#Grapes~@!~";
5
3791
by: shawnmkramer | last post by:
Anyone every heard of the Regex.IsMatch and Regex.Match methods just hanging and eventually getting a message "Requested Service not found"? I have the following pattern: ^(?<OrgCity>(+)+), City of, (?<OrgState>(()|( +\.)))( \((?<OrgCountry>{2,})\))?$ (ignore the line wrap)
3
2206
jlm699
by: jlm699 | last post by:
I have an application that is build on wxPython and have run into a small but annoying problem. I use a Search Control in my toolbar just as in the ToolBar example. Now when the user enters say PrmID def OnTextEntered(self, evt): text = self.GetValue() if re.search('\', text): text.replace(' self.SetMenu(self.MakeMenu()) And the doSearch function... def DoSearch(self, text,...
0
1010
by: rvenable | last post by:
Hi, I have a search engine on our website which searches through each page of the website using regular expressions with ASP 3.0. First, I read in all the contents of the page and remove all html tags with the following pattern: <*> However, this won't work if I have a line like this: <input type="text" name="search" maxlength="50" size="36" value="<%=Request.QueryString("search") %>" /> It finds the < before input and finds the > right...
14
4994
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any text</aClosingTag> I need a Regex that will get all of the text between the html tags above (the html tags are random and i do not know them before hand). The match string always starts with at least 5 digits.
6
15946
by: Zetten | last post by:
I have an AD search module which works as I want it to; searching for a matching forename and/or surname in the appropriate OU. I would like to extend it to be more flexible, so that instead of just searching for a matching string in the surname/forename fields it can match partial strings. I already have it applying a star to the end of the filter, which accomplishes part of this, but I would like it to match partial strings at the start as...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.