psql query problem with varchar and integer

hi,

is it possible to convert a varchar to an integer with a query? something like "select * from table where INT(field) > 90"?

field is of type varchar

thanks for any help
brutebassAsked:
Who is Participating?
 
Brendt HessConnect With a Mentor Senior DBACommented:
Although it isn't clear, it appears that PostgreSQL supports the CAST function.  Thus, try:

SELECT * FROM Table WHERE Cast(Field as Int) > 90

There is also a Cast character combination - two colons (::) that should be usable:

SELECT * FROM Table WHERE Field::Int > 90
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Try this:

select * from table
where TO_NUMBER(field) > 90

Cheers
0
 
brutebassAuthor Commented:
i'm using postgresql v6.5 btw
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
brutebassAuthor Commented:
to_number doesnt work
0
 
kdg2000Commented:
In MS SQL
select * from table where convert(int,field) > 90
0
 
rajeXshCommented:
There is a TO_NUMBER function in PostgreSQL
Here is a link to the documentaion
http://postgresql.cokernet.com/devel-corner/docs/postgres/functions-formatting.html
0
 
brutebassAuthor Commented:
thanks, both solutions you posted work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.