Solved

psql query problem with varchar and integer

Posted on 2001-08-23
7
910 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
null value 15 94
Working with SharePoint Data 8 47
Steps to produce a data strategy 5 43
Exchange 2010 Database wont mount 3 28
This article describes some very basic things about SQL Server filegroups.
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
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…

896 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

19 Experts available now in Live!

Get 1:1 Help Now