![]() ![]() The email in each list separated by a semi-colon. The following example uses the STRING_AGG() function to build an email list for each country. Here is the partial output: B) Using STRING_AGG() function to generate a list of emails This example uses the STRING_AGG() function to return a list of actor’s names for each film from the film table: SELECTį.title Code language: SQL (Structured Query Language) ( sql ) A) Using STRING_AGG() function to generate a list of comma-separated values We will use the film, film_actor, and actor tables from the sample database for the demonstration. PostgreSQL STRING_AGG() function examples Like other aggregate functions such as AVG(), COUNT(), MAX(), MIN(), and SUM(), the STRING_AGG() function is often used with the GROUP BY clause. The return type of the STRING_AGG() function is the string while the return type of the ARRAY_AGG() function is the array. The STRING_AGG() is similar to the ARRAY_AGG() function except for the return type. It has the following form: ORDER BY expression1, Code language: SQL (Structured Query Language) ( sql ) The order_by_clause is an optional clause that specifies the order of concatenated results. separator is the separator for concatenated strings.If you use other types than character string type, you need to explicitly cast these values of that type to the character string type. ![]() expression is any valid expression that can resolve to a character string.The STRING_AGG() function accepts two arguments and an optional ORDER BY clause. The following shows the syntax of the STRING_AGG() function: STRING_AGG ( expression, separator ) Code language: CSS ( css ) The function does not add the separator at the end of the string. The PostgreSQL STRING_AGG() function is an aggregate function that concatenates a list of strings and places a separator between them. Introduction to PostgreSQL STRING_AGG() function Summary: in this tutorial, you will learn how to use the PostgreSQL STRING_AGG() function to concatenate strings and place a separator between them. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |