Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite Query: Translate string.Join and Concat #28100

Closed
bricelam opened this issue May 25, 2022 · 6 comments
Closed

SQLite Query: Translate string.Join and Concat #28100

bricelam opened this issue May 25, 2022 · 6 comments
Assignees

Comments

@bricelam
Copy link
Contributor

These can be translated into the group_concat aggregate function.

.NET SQL
string.Concat(values) group_concat($values, '')
string.Join(separator, values) group_concat($values, $separator)
@roji
Copy link
Member

roji commented May 25, 2022

I've already added some custom aggregate translations for Npgsql (npgsql/efcore.pg#2383), I can probably do the above along with #2981.

@roji
Copy link
Member

roji commented May 25, 2022

Note slight discrepancy between string.Join and group_concat, as group_concat filters out nulls but the string.Join doesn't - you get an empty string. So to get a faithful translation, we'd need to coalesce to empty string. Same thing happens on SQL Server and PG string_agg.

@roji roji self-assigned this May 25, 2022
@roji
Copy link
Member

roji commented May 25, 2022

Poaching (in case it wasn't abundantly clear 😅)

@roji
Copy link
Member

roji commented May 25, 2022

Same as SQL Server (#2981 (comment)):

Null semantics of group_concat
DROP TABLE IF EXISTS data;
CREATE TABLE data
(
    id INT PRIMARY KEY,
    name TEXT
);

-- Simple sample
INSERT INTO data (name) VALUES ('foo'), ('bar');
SELECT group_concat(name, ', ') FROM data; -- foo, bar

-- NULLs are ignored and the corresponding separator is not added
DELETE FROM data WHERE 1=1;
INSERT INTO data (name) VALUES ('foo'), (NULL), ('bar');
SELECT group_concat(name, ', ') FROM data; -- foo, bar

-- NULLs only results in NULL
DELETE FROM data WHERE 1=1;
INSERT INTO data (name) VALUES (NULL);
SELECT group_concat(name, ', ') FROM data; -- NULL

-- Empty table results in NULL
DELETE FROM data WHERE 1=1;
SELECT group_concat(name, ', ') FROM data; -- NULL

@roji
Copy link
Member

roji commented May 25, 2022

Duplicate of #2981

@roji roji marked this as a duplicate of #2981 May 25, 2022
@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2022
@roji
Copy link
Member

roji commented May 25, 2022

Doing this as part of #2981

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants