How to split string in postgresql?

Member

by larissa , in category: MySQL , 3 months ago

How to split string in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 3 months ago

@larissa 

In PostgreSQL, you can split a string using the string_to_array function. Here's an example of how to split a string into an array:

1
SELECT string_to_array('hello world', ' ');


This will return an array with two elements: 'hello' and 'world'.


If you want to split a string based on a different delimiter, you can change the second argument in the string_to_array function. For example, to split a string using a comma as the delimiter, you can do:

1
SELECT string_to_array('apple,banana,orange', ',');


This will return an array with three elements: 'apple', 'banana', and 'orange'.