473,385 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sorting street addresses

Thanks to some help here on the list, I've been able to get addresses
sorting pretty well, but now I have a issue with same addresses on
different streets not grouping the streets. This is what I'm using a
substring search in the ORDER BY statement now like in this view:

SELECT tblhudsimilargroups.rems_id, tblhudsimilargroups.group_id,
tblhudsimilargroups.similar_group_id, tblhudbuildings.address,
tblhudbuildings.hud_building_id,
is_bldg_lbp(tblhudbuildings.hud_building_id) AS is_lbp,
is_bldg_lbp_hazard(tblhudbuildings.hud_building_id ) AS is_lbp_hazard
FROM (tblhudsimilargroups LEFT JOIN tblhudbuildings ON
((tblhudsimilargroups.similar_group_id =
tblhudbuildings.similar_group_id)))
ORDER BY tblhudsimilargroups.rems_id, tblhudsimilargroups.group_id,
("substring"((tblhudbuildings.address)::text,
'[^0-9]+'::text))::character
varying, ("substring"((tblhudbuildings.address)::text,
'^[0-9]+'::text))::integer;

And getting this result:

ohc=> SELECT public.viewbldginfo.group_id, public.viewbldginfo.address
FROM public.viewbldginfo WHERE (public.viewbldginfo.rems_id
='800004136');
group_id | address
----------+--------------------------
A | 3606 ROYALTY COURT
A | 3601/3603 ROYALTY COURT
A | 3602/3604 ROYALTY COURT
A | 3605/3607 ROYALTY COURT
A | 3701/3703 MCKINLEY COURT
A | 3702/3704 MCKINLEY COURT
A | 3705/3707 MCKINLEY COURT
A | 3709/3711 MCKINLEY COURT
A | 7801/7803 SOCIAL CIRCLE
A | 7801/7803 ANDALUSIA
A | 7801/7803 HAVERSHAM
A | 7802/7804 ANDALUSIA
A | 7802/7804 HAVERSHAM
A | 7805/7807 SOCIAL CIRCLE
A | 7806/7808 HAVERSHAM
A | 7811/7813 SOCIAL CIRCLE
A | 7815/7817 SOCIAL CIRCLE
A | 7825/7827 SOCIAL CIRCLE
A | 7833/7835 SOCIAL CIRCLE

I would like all those on the same street grouped together. Is there any
tricks to getting the street names sorted first, possibly where numbers
and strings separate?

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

Nov 23 '05 #1
4 3754
On Thu, Oct 28, 2004 at 03:36:00PM -0400, Robert Fitzpatrick wrote:
I would like all those on the same street grouped together. Is there any
tricks to getting the street names sorted first, possibly where numbers
and strings separate?


You could do something like

CREATE FUNCTION streetname(text) RETURNS text AS '
SELECT substring($1 FROM ''[a-zA-Z ]+$'')
' LANGUAGE 'SQL';

and then add an ORDER BY streetname(address) to your select.

Richard

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

Nov 23 '05 #2
Richard Poole wrote:
On Thu, Oct 28, 2004 at 03:36:00PM -0400, Robert Fitzpatrick wrote:

I would like all those on the same street grouped together. Is there any
tricks to getting the street names sorted first, possibly where numbers
and strings separate?

You could do something like

CREATE FUNCTION streetname(text) RETURNS text AS '
SELECT substring($1 FROM ''[a-zA-Z ]+$'')
' LANGUAGE 'SQL';

and then add an ORDER BY streetname(address) to your select.


You could also add a function index that would help speed things along.

Sincerely,

Joshua D. Drake

Richard

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

--
Command Prompt, Inc., home of PostgreSQL Replication, and plPHP.
Postgresql support, programming shared hosting and dedicated hosting.
+1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com
Mammoth PostgreSQL Replicator. Integrated Replication for PostgreSQL
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #3
How will that work when people reside at
123A Some St.

Address that need to be sorted and/or grouped in any way should be
stored as multiple fields.

door number
door number suffix Most often a letter
street name prefix Section
street name
street name suffix Direcetion
street type St, Cr, Rd etc
subdivision type Unit, Apt, Office etc
subdivision Alphanumeric
City
State
Postal Code


Reformating street address for address correction and for the purpose of
distribution and/or statistics is a pain.

Try these:

105-1234 N 13th St E NY
1234 N 13th E St apt 105
1234 North 13th St East apt 105 New-York
#105 1234 N Thirteenth St E NY

You get my drift... and I did not try appartment letter.

JLL



Richard Poole wrote:
On Thu, Oct 28, 2004 at 03:36:00PM -0400, Robert Fitzpatrick wrote:

I would like all those on the same street grouped together. Is there any
tricks to getting the street names sorted first, possibly where numbers
and strings separate?

You could do something like

CREATE FUNCTION streetname(text) RETURNS text AS '
SELECT substring($1 FROM ''[a-zA-Z ]+$'')
' LANGUAGE 'SQL';

and then add an ORDER BY streetname(address) to your select.

Richard

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


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

Nov 23 '05 #4

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I would like all those on the same street grouped together. Is there any
tricks to getting the street names sorted first, possibly where numbers
and strings separate?


As some have demonstrated, this can be a difficult problem. Your best bet
is not to reinvent the wheel, but find someone who has already solved the
problem. For example:

http://search.cpan.org/dist/Lingua-E...ddressParse.pm

You could easily use the above in a Pl/perl function, or just in Perl
if your application happens to be written in that. Worse case, check out the
source code of the module and see how they have done it and create your
own version.

- --
Greg Sabino Mullane gr**@turnstep.com
PGP Key: 0x14964AC8 200410290722

-----BEGIN PGP SIGNATURE-----

iD8DBQFBgihdvJuQZxSWSsgRAvFBAKC1EcSW5Ru5+nZwNLenbR VqQlQP/wCgpvd6
TOiKff34E+DJVM7rcPkMACU=
=55zK
-----END PGP SIGNATURE-----

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

Nov 23 '05 #5

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

Similar topics

4
by: Sugapablo | last post by:
I have a database table that contains street addresses in the following format: 123 Any St. 456 Some Rd. 7789 That Blvd. etc. I.e. Street number, street name, standard abbriviation of road...
0
by: Bernhard Schmidt | last post by:
Hello, sorry for bothering, I'm not a programmer and I don't do much python, I'm more a networking guy trying to get his favourite linux distribution to update through the shiny new protocol...
1
by: Al Dykes | last post by:
Does anyone have an idea on how to find ZIP+4 codes? Thanks -- a d y k e s @ p a n i x . c o m Don't blame me. I voted for Gore.
2
by: rcamarda | last post by:
I'm thinking of doing some basic parsing of address. I want to seprate out the house number from the street name from the suffix. I have the suffix's from the USPS, but I cant find a database of US...
0
by: noureensyed | last post by:
Hi there, Any ideas on how to sort an xml of the type below. I want to output the exact same xml as well just sorted. However in my case I want to select a particular column tag below, say...
7
by: Raphi | last post by:
Hi, I'm trying to clean up a large database in Access. I have one field for address, which needs to be broken up into Street Number, Street Name, and Street Label (St., Road, etc.) The...
4
by: Tom Warren | last post by:
About once a year or so for the last 10 years, I update my street address parser and I'm starting to look at it again. This parser splits a street address line into its smallest common elements...
0
by: i3enners | last post by:
Hi there I am trying to sort an xml file containing addresses and have nearly managed it, i just cannot get the root element to copy over to the new file. I'm sure its something really simple so...
7
by: Amichai | last post by:
Hi All. I have an xml something like this: <?xml version="1.0" encoding="UTF-8"?> <root> <person> <name>John</name> <family name>Smith</family name> </person>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.