Skip to content

Commit

Permalink
array_position for boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlauvlwj committed Sep 9, 2023
1 parent 687af3d commit 0ce6d32
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,51 @@ public fun arrayPosition(
return arrayPosition(ArgumentExpression(array, LongArraySqlType), value, offset)
}

/**
* 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.
*
* array_position(ARRAY['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'], 'mon') → 2
*/
public fun arrayPosition(
array: ColumnDeclaring<BooleanArray>, value: ColumnDeclaring<Boolean>, offset: Int? = null
): FunctionExpression<Int> {
// array_position(array, value[, offset])
return FunctionExpression(
functionName = "array_position",
arguments = listOfNotNull(
array.asExpression(),
value.asExpression(),
offset?.let { ArgumentExpression(it, IntSqlType) }
),
sqlType = IntSqlType
)
}

/**
* 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.
*
* array_position(ARRAY['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'], 'mon') → 2
*/
public fun arrayPosition(
array: ColumnDeclaring<BooleanArray>, value: Boolean, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(array, ArgumentExpression(value, BooleanSqlType), offset)
}

/**
* 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.
*
* array_position(ARRAY['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'], 'mon') → 2
*/
public fun arrayPosition(
array: BooleanArray, value: ColumnDeclaring<Boolean>, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(ArgumentExpression(array, BooleanArraySqlType), value, offset)
}

/**
* 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.
Expand Down

0 comments on commit 0ce6d32

Please sign in to comment.