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

SQL: CONCAT should return NULL when the field involved has a NULL value? #36169

Closed
astefan opened this issue Dec 3, 2018 · 7 comments · Fixed by #36601
Closed

SQL: CONCAT should return NULL when the field involved has a NULL value? #36169

astefan opened this issue Dec 3, 2018 · 7 comments · Fixed by #36601

Comments

@astefan
Copy link
Contributor

astefan commented Dec 3, 2018

SQL Server 2017, by default, will consider null values in CONCAT() function as empty strings and return a non-null value. But, it also offers the option of changing this setting by using CONCAT_NULL_YIELDS_NULL setting. They do warn, though, that this option will be ON in a future version of SQL Server: https://docs.microsoft.com/en-us/sql/t-sql/statements/set-concat-null-yields-null-transact-sql?view=sql-server-ver15. The preview docs for SQL Server 2019 does still have the option default as OFF (so null is considered empty string).

PostgreSQL will also "ignore" null values and treat them as empty strings: https://www.postgresql.org/docs/11/functions-string.html

@astefan astefan added the :Analytics/SQL SQL querying label Dec 3, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@astefan astefan self-assigned this Dec 3, 2018
@astefan
Copy link
Contributor Author

astefan commented Dec 3, 2018

CC @bpintea

@nik9000
Copy link
Member

nik9000 commented Dec 3, 2018

Generally I'd do what PostgreSQL does unless PostgreSQL is being crazy. It looks like PostgreSQL is fairly reasonable:

test=# SELECT CONCAT(NULL) = '';
 ?column? 
----------
 t
(1 row)

test=# SELECT CONCAT('a', NULL, 'b');
 concat 
--------
 ab
(1 row)

This looks like what SQL Server does by default too. That warning in the PostgreSQL docs seem to be about if you end up with a NULL array and you pass it to CONCAT with the VARIADIC keyword.

@matriv
Copy link
Contributor

matriv commented Dec 4, 2018

Weirdly enough for the || operator postgres behaves differently:

test=# select (null || 'marios') is null;
 ?column?
----------
 t
(1 row)

@matriv
Copy link
Contributor

matriv commented Dec 5, 2018

I would vote to stick with PostgreSQL behaviour as well here.

@costin
Copy link
Member

costin commented Dec 7, 2018

+1. Let's go with Postgres.

@astefan
Copy link
Contributor Author

astefan commented Dec 17, 2018

master (7.0.0): 2ed6ab9
6.x (6.6.0): e187710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants