Andrew
Andrew

Reputation: 8703

Add single quote to string

Given this data:

col1
----
foo
bar

I want concatenate the rows together, and end up with 'foo','bar'. Using collect_set gets me an array, concat_ws gets me a comma separated string. select

concat_ws(',',collect_set(col1))

I cannot figure out how to get the single quotes in there.

concat('''',col1,'''') just returns the value of col1.

What am I doing wrong?

Upvotes: 1

Views: 8247

Answers (1)

ssc-hrep3
ssc-hrep3

Reputation: 16069

You need to escape the quotes.

concat('\'',col1,'\'')

Upvotes: 1

Related Questions