Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

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?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Try...

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

You just need those parenthesis.

share|improve this answer
    
That worked! Thanks to you both. – Brad Mathews Aug 6 '10 at 1:07

Use some extra ():

Update mytable set street = (string_to_array(myfield,'~'))[2]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.