9

I want to parse a field with the following type of value:

"DAVE EBERT CONSTRUCTION~139 LENNOX STREET~SANTA CRUZ, CA 95060~~Business Phone Number:(831) 818-3170"

I would like to do a query like:

Update mytable set street = string_to_array(myfield,'~')[2]

But string_to_array does not "return" an array so it can't be chained in this way. However, it does return an array that can be used by other functions that take arrays like array_upper() so I don't know why it would not work.

My workaround is to create an array field and do this:

Update mytable set myfield_array = string_to_array(myfield,'~')
Update mytable set street = myfield_array[2]

Is there a more direct way to do this? But again, if I am extracting a lot of different array elements, maybe the less direct way performs better because you are converting string to array only once?

2 Answers 2

22

Try...

Update mytable set street = (string_to_array(myfield,'~'))[2]

You just need those parenthesis.

Sign up to request clarification or add additional context in comments.

1 Comment

Why start in 1?
4

Use some extra ():

Update mytable set street = (string_to_array(myfield,'~'))[2]

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.