0

I have a table like below

enter image description here

If I select item_no>'1623' from above table

I want to print the result below

1666
1674
1912
1952
1953

I am trying below command

select * from table where item_no>'1623'

But it's giving wrong result

2 Answers 2

1

use SUBSTRING

select * from t where substring(item_no,'([0-9]+)') :: int  > 1623

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

thanks its worked. and if i select item-no>1623G can i get the result 1623H and 1623I and remaining values
1

Just try to cast item_no as integer ( I suppose it's non-numeric ).

with tab(numbers) as
(
 select nullif(left(item_no, strpos(item_no, '_') - 1),'')::integer from "table"    
)    
select numbers
  from tab
 where numbers > 1623     

( without seeing the picture, considering the comment all of the data end with a non-numeric character ) all data composed of digits upto the last character.

Or, try to extract the digits only as :

with tab(numbers) as
(
 select nullif(regexp_replace(col, '\D','','g'),'')::integer from "table"    
)    
select numbers
  from tab
 where numbers > 1623

Demo

2 Comments

getting below error ERROR: invalid input syntax for integer: "1623G" ********** Error ********** ERROR: invalid input syntax for integer: "1623G" SQL state: 22P02
@joe please share a text that picture I cannot see it. Btw, 1623G is not numeric of course. Do all data end with a G character ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.