-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 support for currently unsupported array functions #4153
Comments
This is amazing, thank you for this roadmap and the ongoing effort to support more array functionality on postgres. |
i'm going to give implementing the method |
I'd like to give |
Hello there! I'd like to give ETA: next week |
I'd like to work on |
Hello! I'll add on |
hi! im doing array_replace |
i'll be working on |
working on |
working on |
I'll be working on |
doin trim_array |
will be working on |
ill do |
@weiznich,i tried some queries on my local postgres instance and it seems this method does not exist in postgres |
@valkrypton https://www.postgresql.org/docs/current/release-16.html#RELEASE-16-FUNCTIONS |
@valkrypton As already pointed out: |
Diesel currently supports the postgres array types. We do not provide built-in support for various operators and methods available for these types. This is a tracking issue for adding support for these operators.
The general strategy for adding support for new methods is as following:
define_sql_function!()
. These operators can be defined here. See the linked definition ofarray_append
for an example. If there is already an existing definition, this step could be skipped. This function should have a short documentation snippet with en examplearray_append
function.#[auto_type]
support for the newly added function hereTRYBUILD=overwrite cargo test
inside ofdiesel_compile_tests
.Method list:
array_append
:( anycompatiblearray, anycompatible ) → anycompatiblearray
: Appends an element to the end of an array (same as the anycompatiblearray || anycompatible operator).array_cat
:( anycompatiblearray, anycompatiblearray ) → anycompatiblearray
: Concatenates two arrays (same as the anycompatiblearray || anycompatiblearray operator). *array_dims
:( anyarray ) → text
: Returns a text representation of the array's dimensions. *array_fill
:( anyelement, integer[] [, integer[] ] ) → anyarray
: Returns an array filled with copies of the given value, having dimensions of the lengths specified by the second argument. The optional third argument supplies lower-bound values for each dimension (which default to all 1). **array_lenght
:( anyarray, integer ) → integer
: Returns the length of the requested array dimension. (Produces NULL instead of 0 for empty or missing array dimensions.) *array_lower
:( anyarray, integer ) → integer
: Returns the lower bound of the requested array dimension *array_ndims
:( anyarray ) → integer
: Returns the number of dimensions of the array. *array_position
:( anycompatiblearray, anycompatible [, integer ] ) → integer
: Returns the subscript of the first occurrence of the second argument in the array, or NULL if it's not present. If the third argument is given, the search begins at that subscript. The array must be one-dimensional. Comparisons are done using IS NOT DISTINCT FROM semantics, so it is possible to search for NULL.**array_positions
:( anycompatiblearray, anycompatible ) → integer[]
: Returns an array of the subscripts of all occurrences of the second argument in the array given as first argument. The array must be one-dimensional. Comparisons are done using IS NOT DISTINCT FROM semantics, so it is possible to search for NULL. NULL is returned only if the array is NULL; if the value is not found in the array, an empty array is returned. *array_prepend
:( anycompatible, anycompatiblearray ) → anycompatiblearray
: Prepends an element to the beginning of an array (same as the anycompatible || anycompatiblearray operator). *array_remove
:( anycompatiblearray, anycompatible ) → anycompatiblearray
: Removes all elements equal to the given value from the array. The array must be one-dimensional. Comparisons are done using IS NOT DISTINCT FROM semantics, so it is possible to remove NULLs. *array_replace
:( anycompatiblearray, anycompatible, anycompatible ) → anycompatiblearray
: Replaces each array element equal to the second argument with the third argument. *array_sample
:( array anyarray, n integer ) → anyarray
: Returns an array of n items randomly selected from array. n may not exceed the length of array's first dimension. If array is multi-dimensional, an “item” is a slice having a given first subscript. *array_shuffle
:( anyarray ) → anyarray
: Randomly shuffles the first dimension of the array. *array_to_string
:( array anyarray, delimiter text [, null_string text ] ) → text
: Converts each array element to its text representation, and concatenates those separated by the delimiter string. If null_string is given and is not NULL, then NULL array entries are represented by that string; otherwise, they are omitted. **array_upper
:( anyarray, integer ) → integer
: Returns the upper bound of the requested array dimension. *cardinality
:( anyarray ) → integer
: Returns the total number of elements in the array, or 0 if the array is empty. *trim_array
:( array anyarray, n integer ) → anyarray
: Trims an array by removing the last n elements. If the array is multidimensional, only the first dimension is trimmed.unnest
:( anyarray ) → setof anyelement
: Expands an array into a set of rows. The array's elements are read out in storage order. ***unnest
:( anyarray, anyarray [, ... ] ) → setof anyelement, anyelement [, ... ]
: Expands multiple arrays (possibly of different data types) into a set of rows. If the arrays are not all the same length then the shorter ones are padded with NULLs. This form is only allowed in a query's FROM clause; see Section 7.2.1.4. ***For items marked with * the instructions above can be followed as written down
For items marked with ** (any function with at least one optional argument) it might be required to define several variants of the function via the
define_sql_type!
macro. We want to have at least one variant for each optional argument, if the argument might be commonly skipped. You need to use a different fitting function name in the definition in these cases + use the#[sql_name = "original_name"]
attribute to map the function correctlyItems marked with *** cannot be implemented yet as diesel doesn't support sets yet.
Please add a comment to this issue if you plan to work on a specific method.
If there is anything unclear about how to add a support for a specific method just ask and we will try to answer your questions.
The text was updated successfully, but these errors were encountered: