LIMIT TO TWO OUTPUT CHARACTERS WITH REGEX - POSTGRESQL

Asked

Viewed 223 times

-1

I have the query below that returns me only the numerical values of my string field, I wanted to limit it to two output characters.

QUERY

SELECT NULLIF(regexp_replace(temperature, '\D','','g'), '')::numeric AS "Temperature"
from tbl_temperature_hosts
where temperature like '%Core 0%' limit 1

OUTPUT

6601205698

EXPECTED OUTCOME

66

1 answer

1


If I understand correctly your problem try:

SELECT LEFT(NULLIF(REGEXP_REPLACE(temperature, '\D','','g'), ''), 2)::numeric AS "Temperature"
FROM tbl_temperature_hosts
WHERE temperature LIKE '%Core 0%' LIMIT 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.