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

add concat as alias for array_append scalar #13635

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

proddata
Copy link
Member

@proddata proddata commented Feb 9, 2023

Summary of the changes / Why this improves CrateDB

add concat(array,element) (and array || element) as alias for array_append(array,element) scalar function in line with PostgreSQL

select [1,2,3] || 4 AS array_append;                                                                                                                                                                             
+--------------+
| array_append |
+--------------+
| [1, 2, 3, 4] |
+--------------+

In line with PostgreSQL (see https://www.postgresql.org/docs/15/functions-array.html)

anycompatiblearray || anycompatible → anycompatiblearray
Concatenates an element onto the end of an array (which must be empty or one-dimensional).
ARRAY[4,5,6] || 7 → {4,5,6,7}

Checklist

  • Added an entry in CHANGES.txt for user facing changes
  • Updated documentation & sql_features table for user facing changes
  • Touched code is covered by tests
  • CLA is signed
  • This does not contain breaking changes, or if it does:
    • It is released within a major release
    • It is recorded in CHANGES.txt
    • It was marked as deprecated in an earlier release if possible
    • You've thought about the consequences and other components are adapted
      (E.g. AdminUI)

@proddata proddata force-pushed the proddata/concat-alias-array-append branch from fa624e3 to e0d75f7 Compare February 9, 2023 14:23
@proddata
Copy link
Member Author

proddata commented Feb 9, 2023

Fails here (sometimes) ...

public void testNormalizeWithNulls() {
assertNormalize("concat(null, null)", isLiteral(""));

cr> SELECT concat(null,null);                                                                                                                                 
+------+
| NULL |
+------+
| NULL |
+------+
SELECT 1 row in set (0.004 sec)
cr> SELECT concat(null::TEXT,null::TEXT);                                                                                                                     
+----+
| '' |
+----+
|    |
+----+
SELECT 1 row in set (0.011 sec)

and here ...

public void testArrayWithAUndefinedInnerType() throws Exception {
assertNormalize("concat([], [1, 2])", isLiteral(List.of(1, 2)));

SELECT concat([], [1, 2]);                                                                                                                                
-- UnsupportedFeatureException[Unknown function: concat([], _array(1, 2)), no overload found for matching argument types: (undefined_array, integer_array). Possible candidates: concat(text, text):text, concat(text):text, concat(array(E), array(E)):array(E), concat(array(E), E):array(E), concat(object, object):object]

I would assume, in both cases it is a problem with precedence? ideas?

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

Successfully merging this pull request may close these issues.

None yet

1 participant