Ask a Question related to PostgreSQL / PGSQL, Design and Development.
-
Clark Endrizzi #1
Natural ordering in postgresql? Does it exist?
Hi all,
I have a field that I'll be ordering and I noticed that ordering is done
logically and would confuse my users here (1,12,16,4,8, etc).
I'm writing an application in PHP that connects to Postgres and while I know
that PHP has some powerful natural ordering functions it would be much
easier if I could just use something from postgres directly. Does there
exist any way to order naturally?
Thanks,
Clark Endrizzi
__________________________________________________ _______________
Is your PC infected? Get a FREE online computer virus scan from McAfee®
Security. [url]http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963[/url]
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
Clark Endrizzi Guest
-
#40418 [NEW]: PQfreemem does not exist prior to Postgresql 7.4
From: wdierkes at 5dollarwhitebox dot org Operating system: Redhat EL 3 (i386 and x86_64) PHP version: 5.2.1 PHP Bug Type: ... -
want to pull natural gas trading prices into flashapplication
I have developed a natural gas calculator that will figure up a persons intrest (royaltys) for a customer of mine. Currently the users will enter... -
Natural order sort
I've written a natural order comparison funtion for the String class. This was based on Martin Pool's "Natural Order String Comparison" which was... -
Natural looking eyes?
I'm having a problem with fixing the red eye (actually WHITE eye) on my pictures. How can I get natural looking eyes when the people have bright... -
Natural penis enlargement - jy0 dq618j wq h
Oh, goodie!! I'll no longer need to sleep standing up with those pesky weights hanging off my 'john thomas'!!! (Didn't do much good, really, but... -
Doug McNaught #2
Re: Natural ordering in postgresql? Does it exist?
"Clark Endrizzi" <clarkendrizzi@hotmail.com> writes:
Sounds like you're storing a number in a text field. Numeric fields> Hi all,
> I have a field that I'll be ordering and I noticed that ordering is
> done logically and would confuse my users here (1,12,16,4,8, etc).
sort in numerical order.
-Doug
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
[url]http://www.postgresql.org/docs/faqs/FAQ.html[/url]
Doug McNaught Guest
-
Ian Harding #3
Re: Natural ordering in postgresql? Does it exist?
Numbers as text are ordered like that. Integers are ordered as you would like.
The best hack I have seen if you are stuck with text is
....order by length(numbers_as_test), numbers_as_text
which sorts first by number of "digits" then by text order.
Ian Harding
Programmer/Analyst II
Tacoma-Pierce County Health Department
[email]iharding@tpchd.org[/email]
Phone: (253) 798-3549
Pager: (253) 754-0002
Hi all,>>> "Clark Endrizzi" <clarkendrizzi@hotmail.com> 12/10/04 1:47 PM >>>
I have a field that I'll be ordering and I noticed that ordering is done
logically and would confuse my users here (1,12,16,4,8, etc).
I'm writing an application in PHP that connects to Postgres and while I know
that PHP has some powerful natural ordering functions it would be much
easier if I could just use something from postgres directly. Does there
exist any way to order naturally?
Thanks,
Clark Endrizzi
__________________________________________________ _______________
Is your PC infected? Get a FREE online computer virus scan from McAfee®
Security. [url]http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963[/url]
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
[url]http://www.postgresql.org/docs/faqs/FAQ.html[/url]
Ian Harding Guest
-
Michael Fuhr #4
Re: Natural ordering in postgresql? Does it exist?
On Fri, Dec 10, 2004 at 02:47:53PM -0700, Clark Endrizzi wrote:
I think you mean that the ordering is done lexically and you want> I have a field that I'll be ordering and I noticed that ordering is done
> logically and would confuse my users here (1,12,16,4,8, etc).
it done numerically. If the fields are entirely numeric then storing
them using one of the numeric types (INTEGER, NUMERIC, DOUBLE
PRECISION, etc.) will result in numeric sort orders. If you have
all-numeric values in VARCHAR/TEXT fields, then you can cast them
to one of the numeric types in the ORDER BY clause:
SELECT ...
ORDER BY fieldname::INTEGER;
If the values are a mixture of text and numbers (e.g., ABC-1, ABC-12,
etc.) then you could use string functions to order different parts
of the field differently:
SELECT ...
ORDER BY SUBSTRING(fieldname, 1, 3),
SUBSTRING(fieldname, 5)::INTEGER;
SELECT ...
ORDER BY SUBSTRING(fieldname FROM '^(\\w+)'),
SUBSTRING(fieldname FROM '(\\d+)')::INTEGER;
--
Michael Fuhr
[url]http://www.fuhr.org/~mfuhr/[/url]
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Michael Fuhr Guest
-
Christopher Browne #5
Re: Natural ordering in postgresql? Does it exist?
Quoth [email]clarkendrizzi@hotmail.com[/email] ("Clark Endrizzi"):
If you wish to impose an ordering on an SQL query, you must specify> I have a field that I'll be ordering and I noticed that ordering is
> done logically and would confuse my users here (1,12,16,4,8, etc).
>
> I'm writing an application in PHP that connects to Postgres and while
> I know that PHP has some powerful natural ordering functions it would
> be much easier if I could just use something from postgres directly.
> Does there exist any way to order naturally?
that ordering using an "ORDER BY" clause.
That's not a PostgreSQL issue; that's how SQL works.
--
output = ("cbbrowne" "@" "gmail.com")
[url]http://linuxfinances.info/info/linux.html[/url]
Rules of the Evil Overlord #204. "I will hire an entire squad of blind
guards. Not only is this in keeping with my status as an equal
opportunity employer, but it will come in handy when the hero becomes
invisible or douses my only light source."
<http://www.eviloverlord.com/>
Christopher Browne Guest
-
Andrey Zinchenko #6
Re: Natural ordering in postgresql? Does it exist?
Michael Fuhr, thank you!
Junior Member
- Join Date
- Nov 2011
- Posts
- 1



Reply With Quote

