Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Currently I have a column call days and the values are 1 day, 2 days etc. I am trying to extract or keep only the numeric value.
Something like:
select CAST(LEFT(days, CHARINDEX(' ', days)) as integer) as #days from daily_table
You could first cast the string to an interval, then use extract():
extract()
select extract(day from days::interval) as "#days" from daily_table;
Add a comment
You can use substring() function to get the numeric value and then cast to INTEGER
select cast(substring(days, 1, position('d' in days)-2) as INTEGER) as "#days" from daily_table;
Required, but never shown
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.
Explore related questions
See similar questions with these tags.