I have this table in PostgreSQL:
Table_T
:
id | body |
---|---|
1 | bla bla bla Call ID: xxx Interaction ID: vvv bla bla |
2 | bla bla bla Call ID: zzz Interaction ID: ooo bla bla |
This is the output I am expecting:
id | Call_id |
---|---|
1 | xxx |
2 | zzz |
This the code I am using:
SELECT id
, substring(body from position('Call ID:' in body)+8 for position('Interaction ID:' in body)- position('Call ID:' in body)+8)
FROM Table_T
I get this error:
Syntax error: Expected "(" or keyword UNNEST but got identifier at
Some documentation I reviewed:
- https://www.postgresql.org/docs/current/functions-string.html
- https://www.w3resource.com/PostgreSQL/position-function.php
- getting "Syntax error: Expected "(" or keyword UNNEST but got identifier…" while converting oracle query to big query
What am I missing?
2
Answers
The error message seems unrelated. The expression works for me. Except that you seem to have your calculation wrong. And it can be done much simpler with
substring()
and a regular expression:fiddle
You can use
regexp_match
:See fiddle.