×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

You will have to retype this query using an explicit cast

You will have to retype this query using an explicit cast

You will have to retype this query using an explicit cast

(OP)
Greetings Techies:

I am seeking some assistance in PSQL - Typecasting.

I have a product catalog created, and I am wanting to implement a price search feature.  I want to allow the customer the oppurnunity to input a range of prices (high/low) that they are willing to pay for a product.  Then I will query the database, and return anything that matches their search.  The problem that I am running into, is that I have the money field in the database setup as type: money.  I need to be able to typecast it to a double, or some floating point value for numeric comparison, as money is a "string" datatype (for apperance on the website).

Here is what I have for results up to now:

ksonline=# select sku, yourcost from catitem where yourcost < 100.00;
ERROR:  Unable to identify an operator '<' for types 'money' and 'float8'
        You will have to retype this query using an explicit cast
ksonline=#
ksonline=# select sku, yourcost from catitem where yourcost::real < 100.00;
ERROR:  Cannot cast type 'money' to 'float4'
ksonline=#
ksonline=# select sku, yourcost from catitem where yourcost::double precision < 100.00;
ERROR:  Cannot cast type 'money' to 'float8'
ksonline=#


Any support you maybe able to provide will be greatly appreciated.  Have a great day!

Ian Wickline
Webmaster, catalog.ksmerchandise.com

RE: You will have to retype this query using an explicit cast

(OP)
Dummy me, I was having a "brain fart" early this morning.  I guess it is just going to be one of them days!

I put the type cast on the wrong side!

The correct cast is:


  select sku, yourcost
    from catitem
   where yourcost < 100.00::money
order by yourcost desc;


Have a great day,
Ian

RE: You will have to retype this query using an explicit cast

One note: The 'money' type is deprecated in PostgreSQL. Generally, it should just be replaced with 'numeric'.

-------------------------------------------

Big Brother: "War is Peace" -- Big Business: "Suspicion is Trust"
(http://www.cl.cam.ac.uk/~rja14/tcpa-faq.html)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close