0

Can someone help what i need to write to find the and print the ID in this string.

with t(txt) as
(
 values
  ('[["+","created_at","20210713T08:30:16.590+02:00"],["+","default_zahlungsverbindung_id",null],["+","firmen_gruppe_id",null],["+","gueltig_bis",null],["+","hat_mahnsperre",false],["+","hat_zahlsperre",false],["+","heimatort",null],["+","id",188710],["+","ist_aktiv",true]]')
)
select 
    substring (txt from ????) as id
from t;

I only want the get 188715 in return. The lenght of the string can change but this part is always the same "id",188710]. So i can say i want everything after "id", until ] but i don't know how.

1 Answer 1

1
with t(txt) as
(
 values
  ('[["+","created_at","20210713T08:30:16.590+02:00"],["+","default_zahlungsverbindung_id",null],["+","firmen_gruppe_id",null],["+","gueltig_bis",null],["+","hat_mahnsperre",false],["+","hat_zahlsperre",false],["+","heimatort",null],["+","id",188710],["+","ist_aktiv",true]]')
)
select regexp_replace(txt, '.*"id"\s*,\s*(\d*)\s*.*]','\1') as id from t;```

ps - it looks like proper json - if its already json in DB, use proper json functions https://www.postgresql.org/docs/current/functions-json.html
Sign up to request clarification or add additional context in comments.

1 Comment

Yes it's json. So your example is not the best way?

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.