Reputation: 4340
I am looking for a method to return the results of an SQLite query as a single string for use in an internal trigger.
Something like Python's 'somestring'.join()
method.
Table: foo
id | name
1 | "foo"
2 | "bar"
3 | "bro"
Then a select statement:
MAGIC_STRING_CONCAT_FUNCTION(SELECT id FROM foo,",");
To return "1,2,3"
Upvotes: 1
Views: 1822
Reputation: 74655
You're looking for the group_concat
function:
group_concat((SELECT id FROM foo), ",");
The following is the description of the function group_concat
from the documentation:
group_concat(X)
group_concat(X,Y)
The
group_concat()
function returns a string which is the concatenation of all non-NULL values ofX
. If parameterY
is present then it is used as the separator between instances ofX
. A comma (",") is used as the separator ifY
is omitted. The order of the concatenated elements is arbitrary.
Upvotes: 2