Solved

psql query problem with varchar and integer

Posted on 2001-08-23
7
898 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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.
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now