Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 119
#SQLServer 88
Oracle 70
#SQL SERVER 35
BRH 31
SQL Server 2012 29
denali 23
#TSQL 19
TSQL 19
C# 15

Archive · View All
October 2011 31
November 2011 30
September 2011 30
August 2011 18
December 2011 15
July 2011 13
June 2011 8
May 2012 4
April 2012 3
January 2010 3

Day 8: String_To_Array function in PostgreSQL

Dec 8 2011 10:39PM by Niladri Biswas   

String_To_Array function in PostgreSQL

Purpose: This functions splits a string to an array provided the delimeter is supplied. It returns an array.

Syntax:String_To_Array(String,delimeter)

Simple Example

Select String_To_Array('Hello World Today I am learning String_To_Array It is very cool',' ')

/* Result */
string_to_array
----------------
{Hello,World,Today,I,am,learning,String_To_Array,It,is,very,cool}

We can figure out that we are splitting the string by blank space which is our delimeter here and the function yielded an array.Every element of the array are demarcated by comma(,).

We can obtain a table of rows if we apply the UnNest function to the output of String_To_Array function

Select UNNEST(String_To_Array('Hello World Today I am learning String_To_Array It is very cool',' '))

/*Result*/
unnest
--------
"Hello"
"World"
"Today"
"I"
"am"
"learning"
"String_To_Array"
"It"
"is"
"very"
"cool"

Example 2: Using String_To_Array on a column

Let us create the environment

CREATE TABLE tblTest( ID Serial NOT NULL, Records TEXT);
INSERT INTO tblTest(Records) VALUES('Hello,World');
INSERT INTO tblTest(Records) VALUES('Today,I,am ,learning, String_To_Array function'); 

SELECT * FROM tblTest;

/*Result*/
"id";"records"
1;"Hello,World"
2;"Today,I,am ,learning, String_To_Array function"

The objective is to split the Records column data. Let us see how

Select 
	ID
	,UnNest(String_To_Array(Records,',')) AS "Splitted Record"
From tblTest;

/* Result*/
id Splitted Record
1  Hello
1  World
2  Today
2  I
2  am 
2  learning
2  String_To_Array function

We can easily write a split function to do this in SQL Server

Hope this helps.

Thanks for reading

Tags: SQL Server, PostgreSQL, #SQL SERVER,


Niladri Biswas
7 · 21% · 6720
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Day 8: String_To_Array function in PostgreSQL" rated 5 out of 5 by 2 readers
Day 8: String_To_Array function in PostgreSQL , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]