Array – How to return a element from the string_to_ARRAY () in PostgreSQL 8.4?

I want to parse a field with the following types of values:

“DAVE EBERT CONSTRUCTION~139 LENNOX STREET~SANTA CRUZ,CA 95060 ~~Business call :(831)818-3170”

I want to make a query like this:

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

But string_to_array does not “return” an array, so it cannot be linked in this way. However, it does return an array, which can be used by other functions, which accept functions like array_upper() Such an array, so I don’t know why it doesn’t work.

My solution is to create an array field and do the following:

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 extract many different array elements, maybe the less straightforward way performs better, because you only convert the string to an array once?

try…

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

You only need those brackets.

I want to use the following types The value of parse a field:

“DAVE EBERT CONSTRUCTION~139 LENNOX STREET~SANTA CRUZ,CA 95060 ~~Business phone: (831)818-3170”

I I want to make a query like this:

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

But string_to_array won’t” Returns” an array, so it cannot be linked in this way. However, it does return an array that can be used by other functions, which accept arrays like array_upper(), so I don’t know why it doesn’t work.

My solution is to create an array field and do the following:

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 extract many different array elements, maybe the less straightforward way performs better, because you only convert the string to an array once?

Try…

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

You only need those brackets.

Leave a Comment

Your email address will not be published.