Solved

psql query problem with varchar and integer

Posted on 2001-08-23
7
950 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:brutebass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6416575
Try this:

select * from table
where TO_NUMBER(field) > 90

Cheers
0
 

Author Comment

by:brutebass
ID: 6416592
i'm using postgresql v6.5 btw
0
 

Author Comment

by:brutebass
ID: 6416599
to_number doesnt work
0
Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

 
LVL 1

Expert Comment

by:kdg2000
ID: 6416665
In MS SQL
select * from table where convert(int,field) > 90
0
 
LVL 2

Expert Comment

by:rajeXsh
ID: 6419605
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
 
LVL 32

Accepted Solution

by:
bhess1 earned 50 total points
ID: 6420518
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
 

Author Comment

by:brutebass
ID: 6420932
thanks, both solutions you posted work.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read about achieving the basic levels of HRIS security in the workplace.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question