0

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

2 Answers 2

2

You could first cast the string to an interval, then use extract():

select extract(day from days::interval) as "#days"
from daily_table;
Sign up to request clarification or add additional context in comments.

Comments

0

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;

Comments

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.