Re: sorting of a price field

From: vinayak <vinpokale(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: sorting of a price field
Date: 2013-09-16 06:46:03
Message-ID: 1379313963507-5771033.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

>I run a fairly simple query to show current records of stock using the
>phrase 'sort by shop_price'.
>Surprise (but really no surprise) this is sorted in ascii order rather
>than shop_price order. So 110.00 comes before 20.00
>I can't see any reference to changing this. What can I do, is this
>perhaps to do with the field type, can it be changed?

may be data type of shop_price is text so you can either type cast it in
below way or alter table and change the data type as numeric(if it is not
violating any other constraints).

select * from table_name order by shop_price::numeric;

-----
Thanks and Regards,
Vinayak Pokale,
NTT DATA OSS Center Pune, India
--
View this message in context: http://postgresql.1045698.n5.nabble.com/sorting-of-a-price-field-tp5770849p5771033.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Albe Laurenz 2013-09-16 06:49:13 Re: PostgreSQL 9.3 Error when trying to run Create Extension postgis
Previous Message Lonni J Friedman 2013-09-16 00:28:36 Re: cannot do backup - locked?