Solved

psql query problem with varchar and integer

Posted on 2001-08-23
7
919 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
7 Comments
 
LVL 142

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

810 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