Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get substring form an integer column

I had a quick question, how can I go about using SUBSTRING on an integer? I currently have field labeled "StoreID" that contains a 5 digit integer (60008). I am trying to use SUBSTRING to remove the 6 when I query out this information. When I use something like:

SUBSTRING('StoreID', 2, 6) I get an error returning back saying that SUBSTRING(integer,integer,integer) does not exist.

Is there another function I can use in postgres to accomplish what I am trying to do?

like image 928
parchambeau Avatar asked Oct 15 '25 13:10

parchambeau


1 Answers

You can cast the integer

SUBSTR(cast (StoreId as text), 2,6)
like image 191
j.holetzeck Avatar answered Oct 18 '25 03:10

j.holetzeck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!