fn

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayAgg

func ArrayAgg(exp builder.Exp) builder.AggBuilder

ArrayAgg builds the array_agg aggregate function.

array_agg ( anynonarray ) → anyarray

Collects all the input values, including nulls, into an array.

array_agg ( anyarray ) → anyarray

Concatenates all the input arrays into an array of one higher dimension.

func ArrayAppend added in v0.13.0

func ArrayAppend(arr builder.Exp, elem builder.Exp) builder.ExpBase

ArrayAppend appends an element to the end of an array.

array_append ( anyarray, anyelement ) → anyarray

func ArrayCat added in v0.13.0

func ArrayCat(arr1 builder.Exp, arr2 builder.Exp) builder.ExpBase

ArrayCat concatenates two arrays.

array_cat ( anyarray, anyarray ) → anyarray

func ArrayDims added in v0.13.0

func ArrayDims(arr builder.Exp) builder.ExpBase

ArrayDims returns a text representation of an array's dimensions.

array_dims ( anyarray ) → text

func ArrayFill added in v0.13.0

func ArrayFill(value builder.Exp, dims builder.Exp, lowerBounds ...builder.Exp) builder.ExpBase

ArrayFill returns an array filled with copies of the given value, having dimensions of the lengths specified by the second argument.

array_fill ( anyelement, integer[] [, integer[] ] ) → anyarray

func ArrayLength added in v0.13.0

func ArrayLength(arr builder.Exp, dim builder.Exp) builder.ExpBase

ArrayLength returns the length of the requested array dimension.

array_length ( anyarray, integer ) → integer

func ArrayLower added in v0.13.0

func ArrayLower(arr builder.Exp, dim builder.Exp) builder.ExpBase

ArrayLower returns the lower bound of the requested array dimension.

array_lower ( anyarray, integer ) → integer

func ArrayNdims added in v0.13.0

func ArrayNdims(arr builder.Exp) builder.ExpBase

ArrayNdims returns the number of dimensions of an array.

array_ndims ( anyarray ) → integer

func ArrayPosition added in v0.13.0

func ArrayPosition(arr builder.Exp, elem builder.Exp, start ...builder.Exp) builder.ExpBase

ArrayPosition returns the subscript of the first occurrence of the second argument in the array, or NULL if it's not present.

array_position ( anyarray, anyelement [, integer ] ) → integer

func ArrayPositions added in v0.13.0

func ArrayPositions(arr builder.Exp, elem builder.Exp) builder.ExpBase

ArrayPositions returns an array of the subscripts of all occurrences of the second argument in the array given as first argument.

array_positions ( anyarray, anyelement ) → integer[]

func ArrayPrepend added in v0.13.0

func ArrayPrepend(elem builder.Exp, arr builder.Exp) builder.ExpBase

ArrayPrepend prepends an element to the beginning of an array.

array_prepend ( anyelement, anyarray ) → anyarray

func ArrayRemove added in v0.13.0

func ArrayRemove(arr builder.Exp, elem builder.Exp) builder.ExpBase

ArrayRemove removes all occurrences of the given value from the array.

array_remove ( anyarray, anyelement ) → anyarray

func ArrayReplace added in v0.13.0

func ArrayReplace(arr builder.Exp, from builder.Exp, to builder.Exp) builder.ExpBase

ArrayReplace replaces each array element equal to the second argument with the third argument.

array_replace ( anyarray, anyelement, anyelement ) → anyarray

func ArrayToString added in v0.13.0

func ArrayToString(arr builder.Exp, delim builder.Exp, nullString ...builder.Exp) builder.ExpBase

ArrayToString concatenates array elements using the supplied delimiter and optional null string.

array_to_string ( anyarray, text [, text ] ) → text

func ArrayUpper added in v0.13.0

func ArrayUpper(arr builder.Exp, dim builder.Exp) builder.ExpBase

ArrayUpper returns the upper bound of the requested array dimension.

array_upper ( anyarray, integer ) → integer

func Avg

func Avg(exp builder.Exp) builder.AggBuilder

Avg builds the avg aggregate function.

avg ( T ) → T

Computes the average (arithmetic mean) of all the non-null input values.

func BitAnd

func BitAnd(exp builder.Exp) builder.AggBuilder

BitAnd builds the bit_and aggregate function.

bit_and ( T ) → T

Computes the bitwise AND of all non-null input values.

func BitOr

func BitOr(exp builder.Exp) builder.AggBuilder

BitOr builds the bit_or aggregate function.

bit_or ( T ) → T

Computes the bitwise OR of all non-null input values.

func BitXor

func BitXor(exp builder.Exp) builder.AggBuilder

BitXor builds the bit_xor aggregate function.

bit_xor ( T ) → T

Computes the bitwise exclusive OR of all non-null input values. Can be useful as a checksum for an unordered set of values.

func BoolAnd

func BoolAnd(exp builder.Exp) builder.AggBuilder

BoolAnd builds the bool_and aggregate function.

bool_and ( boolean ) → boolean

Returns true if all non-null input values are true, otherwise false.

func BoolOr

func BoolOr(exp builder.Exp) builder.AggBuilder

BoolOr builds the bool_or aggregate function.

bool_or ( boolean ) → boolean

Returns true if any non-null input value is true, otherwise false.

func Count

func Count(exp builder.Exp) builder.AggBuilder

Count builds the count aggregate function.

count ( * ) → bigint

Computes the number of input rows.

count ( expression ) → bigint

Computes the number of input rows in which the input value is not null.

Example:

builder.Select(fn.Count(builder.N("*"))).From("table")

func CumeDist

func CumeDist(args ...builder.Exp) builder.AggBuilder

CumeDist builds the cume_dist aggregate function.

cume_dist ( args ) WITHIN GROUP ( ORDER BY sorted_args ) → double precision

Computes the cumulative distribution, that is (number of rows preceding or peers with hypothetical row) / (total rows). The value thus ranges from 1/N to 1.

func DenseRank

func DenseRank(args ...builder.Exp) builder.AggBuilder

DenseRank builds the dense_rank aggregate function.

dense_rank ( args ) WITHIN GROUP ( ORDER BY sorted_args ) → bigint

Computes the rank of the hypothetical row, without gaps; this function effectively counts peer groups.

func Extract added in v0.2.2

func Extract(field string, from builder.Exp) builder.ExpBase

Extract builds the EXTRACT(field FROM source) function.

func FirstValue added in v0.11.1

func FirstValue(value builder.Exp) builder.WindowFuncBuilder

FirstValue builds the first_value window function.

first_value ( value anyelement ) → anyelement

Returns value evaluated at the row that is the first row of the window frame.

func GenerateSeries added in v0.13.0

func GenerateSeries(start builder.Exp, stop builder.Exp, step ...builder.Exp) builder.FuncBuilder

GenerateSeries builds a generate_series functional call.

generate_series ( start, stop ) → setof integer
generate_series ( start, stop ) → setof bigint
generate_series ( start, stop, step ) → setof integer
generate_series ( start, stop, step ) → setof bigint
generate_series ( start, stop, step interval ) → setof timestamp
generate_series ( start, stop, step interval ) → setof timestamp with time zone

Generates a series of values from start to stop, with a step size of one if not specified, or step if specified.

Examples from PostgreSQL documentation:

SELECT * FROM generate_series(2,4);
 generate_series
-----------------
               2
               3
               4
(3 rows)

SELECT * FROM generate_series(5,1,-2);
 generate_series
-----------------
               5
               3
               1
(3 rows)

SELECT * FROM generate_series(4,3);
 generate_series
-----------------
(0 rows)

SELECT current_date + s.a AS dates FROM generate_series(0,14,7) AS s(a);
   dates
------------
 2004-02-05
 2004-02-12
 2004-02-19
(3 rows)

SELECT * FROM generate_series('2008-03-01 00:00'::timestamp,
                              '2008-03-04 12:00', '10 hours');
   generate_series
---------------------
 2008-03-01 00:00:00
 2008-03-01 10:00:00
 2008-03-01 20:00:00
 2008-03-02 06:00:00
 2008-03-02 16:00:00
 2008-03-03 02:00:00
 2008-03-03 12:00:00
 2008-03-03 22:00:00
 2008-03-04 08:00:00
(9 rows)

func GenerateSubscripts added in v0.13.0

func GenerateSubscripts(array builder.Exp, dim builder.Exp, reverse ...builder.Exp) builder.FuncBuilder

GenerateSubscripts builds a generate_subscripts functional call.

generate_subscripts ( array anyarray, dim integer ) → setof integer
generate_subscripts ( array anyarray, dim integer, reverse boolean ) → setof integer

Generates a series comprising the subscripts of the dim'th dimension of the given array. When reverse is true, returns the series in reverse order.

Examples from PostgreSQL documentation:

SELECT generate_subscripts('{NULL,1,NULL,2}'::int[], 1) AS s;
 s
---
 1
 2
 3
 4
(4 rows)

-- unnest a 2D array
CREATE OR REPLACE FUNCTION unnest2(anyarray)
RETURNS SETOF anyelement AS $$
select $1[i][j]
   from generate_subscripts($1,1) g1(i),
        generate_subscripts($1,2) g2(j);
$$ LANGUAGE sql IMMUTABLE;
CREATE FUNCTION
SELECT * FROM unnest2(ARRAY[[1,2],[3,4]]);
 unnest2
---------
       1
       2
       3
       4
(4 rows)

When using generate_subscripts in the FROM clause, it's useful to also have the array value itself:

-- set returning function WITH ORDINALITY
SELECT a AS array, s AS subscript, a[s] AS value
FROM (SELECT generate_subscripts(a, 1) AS s, a FROM arrays) foo;
     array     | subscript | value
---------------+-----------+-------
 {-1,-2}       |         1 |    -1
 {-1,-2}       |         2 |    -2
 {100,200,300} |         1 |   100
 {100,200,300} |         2 |   200
 {100,200,300} |         3 |   300
(5 rows)

func Grouping

func Grouping(exps ...builder.Exp) builder.AggBuilder

Grouping builds the grouping operation.

GROUPING ( group_by_expression(s) ) → integer

Returns a bit mask indicating which GROUP BY expressions are not included in the current grouping set. Bits are assigned with the rightmost argument corresponding to the least-significant bit; each bit is 0 if the corresponding expression is included in the grouping criteria of the grouping set generating the current result row, and 1 if it is not included.

func Initcap added in v0.5.1

func Initcap(identer builder.Exp) builder.ExpBase

func JsonAgg

func JsonAgg(exp builder.Exp) builder.AggBuilder

JsonAgg builds the json_agg aggregate function.

json_agg ( anyelement ) → json

Collects all the input values, including nulls, into a JSON array. Values are converted to JSON as per to_json.

func JsonArrayElements added in v0.8.0

func JsonArrayElements(exp builder.Exp) builder.ExpBase

JsonArrayElements builds the json_array_elements function.

( json ) → setof json

Expands the top-level JSON array into a set of JSON values.

func JsonArrayElementsText added in v0.8.0

func JsonArrayElementsText(exp builder.Exp) builder.ExpBase

JsonArrayElementsText builds the json_array_elements_text function.

( json ) → setof text

Expands the top-level JSON array into a set of text values.

func JsonArrayLength added in v0.8.0

func JsonArrayLength(exp builder.Exp) builder.ExpBase

JsonArrayLength builds the json_array_length function.

( json ) → integer

Returns the number of elements in the top-level JSON array.

func JsonBuildObject

func JsonBuildObject() builder.JsonBuildObjectBuilder

JsonBuildObject builds the json_build_object function. It is based on a builder pattern to specify properties (see builder.JsonBuildObjectBuilder).

( VARIADIC "any" ) → json

Builds a JSON object out of a variadic argument list. By convention, the argument list consists of alternating keys and values. Key arguments are coerced to text; value arguments are converted as per to_json.

func JsonEach added in v0.8.0

func JsonEach(exp builder.Exp) builder.ExpBase

JsonEach builds the json_each function.

( json ) → setof record ( key text, value json )

Expands the top-level JSON object into a set of key/value pairs.

func JsonEachText added in v0.8.0

func JsonEachText(exp builder.Exp) builder.ExpBase

JsonEachText builds the json_each_text function.

( json ) → setof record ( key text, value text )

Expands the top-level JSON object into a set of key/value pairs. The returned values will be of type text.

func JsonExtractPath added in v0.8.0

func JsonExtractPath(fromJson builder.Exp, pathElems ...builder.Exp) builder.ExpBase

JsonExtractPath builds the json_extract_path function.

( from_json json, VARIADIC path_elems text[] ) → json

Extracts JSON sub-object at the specified path. (This is functionally equivalent to the #> operator, but writing the path out as a variadic list can be more convenient in some cases.)

func JsonExtractPathText added in v0.8.0

func JsonExtractPathText(fromJson builder.Exp, pathElems ...builder.Exp) builder.ExpBase

JsonExtractPathText builds the json_extract_path_text function.

( from_json json, VARIADIC path_elems text[] ) → text

Extracts JSON sub-object at the specified path as text. (This is functionally equivalent to the #>> operator.)

func JsonObjectAgg

func JsonObjectAgg(key, value builder.Exp) builder.AggBuilder

JsonObjectAgg builds the json_object_agg aggregate function.

json_object_agg ( key "any", value "any" ) → json

Collects all the key/value pairs into a JSON object. Key arguments are coerced to text; value arguments are converted as per to_json. Values can be null, but not keys.

func JsonObjectKeys added in v0.8.0

func JsonObjectKeys(exp builder.Exp) builder.ExpBase

JsonObjectKeys builds the json_object_keys function.

( json ) → setof text

Returns the set of keys in the top-level JSON object.

func JsonPopulateRecord added in v0.8.0

func JsonPopulateRecord(base builder.Exp, fromJson builder.Exp) builder.ExpBase

JsonPopulateRecord builds the json_populate_record function.

( base anyelement, from_json json ) → anyelement

Expands the top-level JSON object to a row having the composite type of the base argument. The JSON object is scanned for fields whose names match column names of the output row type, and their values are inserted into those columns of the output. (Fields that do not correspond to any output column name are ignored.) In typical use, the value of base is just NULL, which means that any output columns that do not match any object field will be filled with nulls. However, if base isn't NULL then the values it contains will be used for unmatched columns.

func JsonPopulateRecordset added in v0.8.0

func JsonPopulateRecordset(base builder.Exp, fromJson builder.Exp) builder.ExpBase

JsonPopulateRecordset builds the json_populate_recordset function.

( base anyelement, from_json json ) → setof anyelement

Expands the top-level JSON array of objects to a set of rows having the composite type of the base argument. Each element of the JSON array is processed as described above for json[b]_populate_record.

func JsonStripNulls added in v0.8.0

func JsonStripNulls(exp builder.Exp) builder.ExpBase

JsonStripNulls builds the json_strip_nulls function.

( json ) → json

Deletes all object fields that have null values from the given JSON value, recursively. Null values that are not object fields are untouched.

func JsonToRecord added in v0.8.0

func JsonToRecord(exp builder.Exp) builder.FuncBuilder

JsonToRecord builds the json_to_record function.

( json ) → record

Expands the top-level JSON object to a row having the composite type defined by an AS clause. (As with all functions returning record, the calling query must explicitly define the structure of the record with an AS clause.) The output record is filled from fields of the JSON object, in the same way as described above for json[b]_populate_record. Since there is no input record value, unmatched columns are always filled with nulls.

func JsonToRecordset added in v0.8.0

func JsonToRecordset(exp builder.Exp) builder.FuncBuilder

JsonToRecordset builds the json_to_recordset function.

( json ) → setof record

Expands the top-level JSON array of objects to a set of rows having the composite type defined by an AS clause. (As with all functions returning record, the calling query must explicitly define the structure of the record with an AS clause.) Each element of the JSON array is processed as described above for json[b]_populate_record.

func JsonTypeof added in v0.8.0

func JsonTypeof(exp builder.Exp) builder.ExpBase

JsonTypeof builds the json_typeof function.

( json ) → text

Returns the type of the top-level JSON value as a text string. Possible types are object, array, string, number, boolean, and null. (The null result should not be confused with an SQL NULL; see the examples.)

func JsonbAgg

func JsonbAgg(exp builder.Exp) builder.AggBuilder

JsonbAgg builds the json_agg aggregate function.

jsonb_agg ( anyelement ) → jsonb

Collects all the input values, including nulls, into a JSON array. Values are converted to JSON as per to_jsonb.

func JsonbArrayElements added in v0.8.0

func JsonbArrayElements(exp builder.Exp) builder.ExpBase

JsonbArrayElements builds the jsonb_array_elements function.

( jsonb ) → setof jsonb

Expands the top-level JSON array into a set of JSON values.

func JsonbArrayElementsText added in v0.8.0

func JsonbArrayElementsText(exp builder.Exp) builder.ExpBase

JsonbArrayElementsText builds the jsonb_array_elements_text function.

( jsonb ) → setof text

Expands the top-level JSON array into a set of text values.

func JsonbArrayLength added in v0.8.0

func JsonbArrayLength(exp builder.Exp) builder.ExpBase

JsonbArrayLength builds the jsonb_array_length function.

( jsonb ) → integer

Returns the number of elements in the top-level JSON array.

func JsonbBuildObject added in v0.5.0

func JsonbBuildObject() builder.JsonBuildObjectBuilder

JsonbBuildObject builds the json_build_object function. It is based on a builder pattern to specify properties (see builder.JsonBuildObjectBuilder).

( VARIADIC "any" ) → jsonb

Builds a JSON object out of a variadic argument list. By convention, the argument list consists of alternating keys and values. Key arguments are coerced to text; value arguments are converted as per to_jsonb.

func JsonbEach added in v0.8.0

func JsonbEach(exp builder.Exp) builder.ExpBase

JsonbEach builds the jsonb_each function.

( jsonb ) → setof record ( key text, value jsonb )

Expands the top-level JSON object into a set of key/value pairs.

func JsonbEachText added in v0.8.0

func JsonbEachText(exp builder.Exp) builder.ExpBase

JsonbEachText builds the jsonb_each_text function.

( jsonb ) → setof record ( key text, value text )

Expands the top-level JSON object into a set of key/value pairs. The returned values will be of type text.

func JsonbExtractPath added in v0.8.0

func JsonbExtractPath(fromJson builder.Exp, pathElems ...builder.Exp) builder.ExpBase

JsonbExtractPath builds the json_extract_path function.

( from_json jsonb, VARIADIC path_elems text[] ) → jsonb

Extracts JSON sub-object at the specified path. (This is functionally equivalent to the #> operator, but writing the path out as a variadic list can be more convenient in some cases.)

func JsonbExtractPathText added in v0.8.0

func JsonbExtractPathText(fromJson builder.Exp, pathElems ...builder.Exp) builder.ExpBase

JsonbExtractPathText builds the jsonb_extract_path_text function.

( from_json jsonb, VARIADIC path_elems text[] ) → text

Extracts JSON sub-object at the specified path as text. (This is functionally equivalent to the #>> operator.)

func JsonbInsert added in v0.8.0

func JsonbInsert(target builder.Exp, path builder.Exp, newValue builder.Exp, insertAfter ...builder.Exp) builder.ExpBase

JsonbInsert builds the jsonb_insert function.

( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb

Returns target with new_value inserted. If the item designated by the path is an array element, new_value will be inserted before that item if insert_after is false (which is the default), or after it if insert_after is true. If the item designated by the path is an object field, new_value will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the target is returned unchanged. As with the path oriented operators, negative integers that appear in the path count from the end of JSON arrays. If the last path step is an array index that is out of range, the new value is added at the beginning of the array if the index is negative, or at the end of the array if it is positive.

func JsonbObjectAgg

func JsonbObjectAgg(key, value builder.Exp) builder.AggBuilder

JsonbObjectAgg builds the jsonb_object_agg aggregate function.

jsonb_object_agg ( key "any", value "any" ) → jsonb

Collects all the key/value pairs into a JSON object. Key arguments are coerced to text; value arguments are converted as per to_jsonb. Values can be null, but not keys.

func JsonbObjectKeys added in v0.8.0

func JsonbObjectKeys(exp builder.Exp) builder.ExpBase

JsonbObjectKeys builds the jsonb_object_keys function.

( jsonb ) → setof text

Returns the set of keys in the top-level JSON object.

func JsonbPathExists added in v0.8.0

func JsonbPathExists(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathExists builds the jsonb_path_exists function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean

Checks whether the JSON path returns any item for the specified JSON value. If the vars argument is specified, it must be a JSON object, and its fields provide named values to be substituted into the jsonpath expression. If the silent argument is specified and is true, the function suppresses the same errors as the @? and @@ operators do.

func JsonbPathExistsTZ added in v0.8.0

func JsonbPathExistsTZ(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathExistsTZ builds the jsonb_path_exists function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean

Checks whether the JSON path returns any item for the specified JSON value. If the vars argument is specified, it must be a JSON object, and its fields provide named values to be substituted into the jsonpath expression. If the silent argument is specified and is true, the function suppresses the same errors as the @? and @@ operators do. This function acts like its counterpart without the _tz suffix, except that this functions supports comparisons of date/time values that require timezone-aware conversions. Due to this dependency, this function is marked as stable, which means this function cannot be used in indexes. The counterpart is immutable, and so can be used in indexes; but it will throw errors if asked to make such comparisons.

func JsonbPathMatch added in v0.8.0

func JsonbPathMatch(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathMatch builds the jsonb_path_match function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean

Returns the result of a JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then NULL is returned. The optional vars and silent arguments act the same as for jsonb_path_exists.

func JsonbPathMatchTZ added in v0.8.0

func JsonbPathMatchTZ(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathMatchTZ builds the jsonb_path_match function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean

Returns the result of a JSON path predicate check for the specified JSON value. Only the first item of the result is taken into account. If the result is not Boolean, then NULL is returned. The optional vars and silent arguments act the same as for jsonb_path_exists. This function acts like its counterpart without the _tz suffix, except that this functions supports comparisons of date/time values that require timezone-aware conversions. Due to this dependency, this function is marked as stable, which means this function cannot be used in indexes. The counterpart is immutable, and so can be used in indexes; but it will throw errors if asked to make such comparisons.

func JsonbPathQuery added in v0.8.0

func JsonbPathQuery(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathQuery builds the jsonb_path_query function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → setof jsonb

Returns all JSON items returned by the JSON path for the specified JSON value. The optional vars and silent arguments act the same as for jsonb_path_exists.

func JsonbPathQueryArray added in v0.8.0

func JsonbPathQueryArray(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathQueryArray builds the jsonb_path_query_array function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb

Returns all JSON items returned by the JSON path for the specified JSON value, as a JSON array. The optional vars and silent arguments act the same as for jsonb_path_exists.

func JsonbPathQueryArrayTZ added in v0.8.0

func JsonbPathQueryArrayTZ(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathQueryArrayTZ builds the jsonb_path_query_array function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb

Returns all JSON items returned by the JSON path for the specified JSON value, as a JSON array. The optional vars and silent arguments act the same as for jsonb_path_exists. This function acts like its counterpart without the _tz suffix, except that this functions supports comparisons of date/time values that require timezone-aware conversions. Due to this dependency, this function is marked as stable, which means this function cannot be used in indexes. The counterpart is immutable, and so can be used in indexes; but it will throw errors if asked to make such comparisons.

func JsonbPathQueryFirst added in v0.8.0

func JsonbPathQueryFirst(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathQueryFirst builds the jsonb_path_query_first function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb

Returns the first JSON item returned by the JSON path for the specified JSON value. Returns NULL if there are no results. The optional vars and silent arguments act the same as for jsonb_path_exists.

func JsonbPathQueryFirstTZ added in v0.8.0

func JsonbPathQueryFirstTZ(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathQueryFirstTZ builds the jsonb_path_query_first function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb

Returns the first JSON item returned by the JSON path for the specified JSON value. Returns NULL if there are no results. The optional vars and silent arguments act the same as for jsonb_path_exists. This function acts like its counterpart without the _tz suffix, except that this functions supports comparisons of date/time values that require timezone-aware conversions. Due to this dependency, this function is marked as stable, which means this function cannot be used in indexes. The counterpart is immutable, and so can be used in indexes; but it will throw errors if asked to make such comparisons.

func JsonbPathQueryTZ added in v0.8.0

func JsonbPathQueryTZ(target builder.Exp, path builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbPathQueryTZ builds the jsonb_path_query function.

( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → setof jsonb

Returns all JSON items returned by the JSON path for the specified JSON value. The optional vars and silent arguments act the same as for jsonb_path_exists. This function acts like its counterpart without the _tz suffix, except that this functions supports comparisons of date/time values that require timezone-aware conversions. Due to this dependency, this function is marked as stable, which means this function cannot be used in indexes. The counterpart is immutable, and so can be used in indexes; but it will throw errors if asked to make such comparisons.

func JsonbPopulateRecord added in v0.8.0

func JsonbPopulateRecord(base builder.Exp, fromJson builder.Exp) builder.ExpBase

JsonbPopulateRecord builds the jsonb_populate_record function.

( base anyelement, from_json jsonb ) → anyelement

Expands the top-level JSON object to a row having the composite type of the base argument. The JSON object is scanned for fields whose names match column names of the output row type, and their values are inserted into those columns of the output. (Fields that do not correspond to any output column name are ignored.) In typical use, the value of base is just NULL, which means that any output columns that do not match any object field will be filled with nulls. However, if base isn't NULL then the values it contains will be used for unmatched columns.

func JsonbPopulateRecordset added in v0.8.0

func JsonbPopulateRecordset(base builder.Exp, fromJson builder.Exp) builder.ExpBase

JsonbPopulateRecordset builds the jsonb_populate_recordset function.

( base anyelement, from_json jsonb ) → setof anyelement

Expands the top-level JSON array of objects to a set of rows having the composite type of the base argument. Each element of the JSON array is processed as described above for json[b]_populate_record.

func JsonbPretty added in v0.8.0

func JsonbPretty(exp builder.Exp) builder.ExpBase

JsonbPretty builds the jsonb_pretty function.

( jsonb ) → text

Converts the given JSON value to pretty-printed, indented text.

func JsonbSet added in v0.8.0

func JsonbSet(target builder.Exp, path builder.Exp, newValue builder.Exp, createIfMissing ...builder.Exp) builder.ExpBase

JsonbSet builds the jsonb_set function.

( target jsonb, path text[], new_value jsonb [, create_if_missing boolean ] ) → jsonb

Returns target with the item designated by path replaced by new_value, or with new_value added if create_if_missing is true (which is the default) and the item designated by path does not exist. All earlier steps in the path must exist, or the target is returned unchanged. As with the path oriented operators, negative integers that appear in the path count from the end of JSON arrays. If the last path step is an array index that is out of range, and create_if_missing is true, the new value is added at the beginning of the array if the index is negative, or at the end of the array if it is positive.

func JsonbSetLax added in v0.8.0

func JsonbSetLax(target builder.Exp, path builder.Exp, newValue builder.Exp, options ...builder.Exp) builder.ExpBase

JsonbSetLax builds the jsonb_set_lax function.

( target jsonb, path text[], new_value jsonb [, create_if_missing boolean [, null_value_treatment text ]] ) → jsonb

If new_value is not NULL, behaves identically to jsonb_set. Otherwise behaves according to the value of null_value_treatment which must be one of 'raise_exception', 'use_json_null', 'delete_key', or 'return_target'. The default is 'use_json_null'.

func JsonbStripNulls added in v0.8.0

func JsonbStripNulls(exp builder.Exp) builder.ExpBase

JsonbStripNulls builds the jsonb_strip_nulls function.

( jsonb ) → jsonb

Deletes all object fields that have null values from the given JSON value, recursively. Null values that are not object fields are untouched.

func JsonbToRecord added in v0.8.0

func JsonbToRecord(exp builder.Exp) builder.FuncBuilder

JsonbToRecord builds the jsonb_to_record function.

( jsonb ) → record

Expands the top-level JSON object to a row having the composite type defined by an AS clause. (As with all functions returning record, the calling query must explicitly define the structure of the record with an AS clause.) The output record is filled from fields of the JSON object, in the same way as described above for json[b]_populate_record. Since there is no input record value, unmatched columns are always filled with nulls.

func JsonbToRecordset added in v0.8.0

func JsonbToRecordset(exp builder.Exp) builder.FuncBuilder

JsonbToRecordset builds the jsonb_to_recordset function.

( jsonb ) → setof record

Expands the top-level JSON array of objects to a set of rows having the composite type defined by an AS clause. (As with all functions returning record, the calling query must explicitly define the structure of the record with an AS clause.) Each element of the JSON array is processed as described above for json[b]_populate_record.

func JsonbTypeof added in v0.8.0

func JsonbTypeof(exp builder.Exp) builder.ExpBase

JsonbTypeof builds the jsonb_typeof function.

( jsonb ) → text

Returns the type of the top-level JSON value as a text string. Possible types are object, array, string, number, boolean, and null. (The null result should not be confused with an SQL NULL; see the examples.)

func Lag added in v0.11.1

func Lag(value builder.Exp, offsetAndDefault ...builder.Exp) builder.WindowFuncBuilder

Lag builds the lag window function.

lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible

Returns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead returns default (which must be of a type compatible with value). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.

func LastValue added in v0.11.1

func LastValue(value builder.Exp, offsetAndDefault ...builder.Exp) builder.WindowFuncBuilder

LastValue builds the last_value window function.

last_value ( value anyelement ) → anyelement

Returns value evaluated at the row that is the last row of the window frame.

func Lead added in v0.11.1

func Lead(value builder.Exp, offsetAndDefault ...builder.Exp) builder.WindowFuncBuilder

Lead builds the lead window function.

lead ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible

Returns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, instead returns default (which must be of a type compatible with value). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.

func Lower added in v0.5.1

func Lower(identer builder.Exp) builder.ExpBase

func Max

func Max(exp builder.Exp) builder.AggBuilder

Max builds the max aggregate function.

max ( see text ) → same as input type

Computes the maximum of the non-null input values. Available for any numeric, string, date/time, or enum type, as well as inet, interval, money, oid, pg_lsn, tid, xid8, and arrays of any of these types.

func Min

func Min(exp builder.Exp) builder.AggBuilder

Min builds the min aggregate function.

min ( see text ) → same as input type

Computes the minimum of the non-null input values. Available for any numeric, string, date/time, or enum type, as well as inet, interval, money, oid, pg_lsn, tid, xid8, and arrays of any of these types.

func Mode

func Mode() builder.AggBuilder

Mode builds the mode aggregate function.

mode () WITHIN GROUP ( ORDER BY anyelement ) → anyelement

Computes the mode, the most frequent value of the aggregated argument (arbitrarily choosing the first one if there are multiple equally-frequent values). The aggregated argument must be of a sortable type.

func NthValue added in v0.11.1

func NthValue(value builder.Exp, n builder.Exp) builder.WindowFuncBuilder

NthValue builds the nth_value window function.

nth_value ( value anyelement, n integer ) → anyelement

Returns value evaluated at the row that is the n'th row of the window frame (counting from 1); returns NULL if there is no such row.

func Ntile added in v0.11.1

func Ntile(numBuckets builder.Exp) builder.WindowFuncBuilder

Ntile builds the ntile window function.

ntile ( num_buckets integer ) → integer

Returns an integer ranging from 1 to the argument value, dividing the partition as equally as possible.

func PercentRank

func PercentRank(args ...builder.Exp) builder.AggBuilder

PercentRank builds the percent_rank aggregate function.

percent_rank ( args ) WITHIN GROUP ( ORDER BY sorted_args ) → double precision

Computes the relative rank of the hypothetical row, that is (rank - 1) / (total rows - 1). The value thus ranges from 0 to 1 inclusive.

func PercentileCont

func PercentileCont(fraction builder.Exp) builder.AggBuilder

PercentileCont builds the percentile_cont aggregate function.

percentile_cont ( fraction double precision ) WITHIN GROUP ( ORDER BY double precision ) → double precision
percentile_cont ( fraction double precision ) WITHIN GROUP ( ORDER BY interval ) → interval
percentile_cont ( fractions double precision[] ) WITHIN GROUP ( ORDER BY double precision ) → double precision[]
percentile_cont ( fractions double precision[] ) WITHIN GROUP ( ORDER BY interval ) → interval[]

Computes the continuous percentile, a value corresponding to the specified fraction within the ordered set of aggregated argument values. This will interpolate between adjacent input items if needed.

func PercentileDisc

func PercentileDisc(fraction builder.Exp) builder.AggBuilder

PercentileDisc builds the percentile_disc aggregate function.

percentile_disc ( fraction double precision ) WITHIN GROUP ( ORDER BY anyelement ) → anyelement

Computes the discrete percentile, the first value within the ordered set of aggregated argument values whose position in the ordering equals or exceeds the specified fraction. The aggregated argument must be of a sortable type.

percentile_disc ( fractions double precision[] ) WITHIN GROUP ( ORDER BY anyelement ) → anyarray

Computes multiple discrete percentiles. The result is an array of the same dimensions as the fractions parameter, with each non-null element replaced by the input value corresponding to that percentile. The aggregated argument must be of a sortable type.

func RangeAgg

func RangeAgg(value builder.Exp) builder.AggBuilder

RangeAgg builds the range_agg aggregate function.

range_agg ( value anyrange ) → anymultirange
range_agg ( value anymultirange ) → anymultirange

Computes the union of the non-null input values.

func RangeIntersectAgg

func RangeIntersectAgg(value builder.Exp) builder.AggBuilder

RangeIntersectAgg builds the range_intersect_agg aggregate function.

range_intersect_agg ( value anyrange ) → anyrange
range_intersect_agg ( value anymultirange ) → anymultirange

Computes the intersection of the non-null input values.

func Rank

func Rank(args ...builder.Exp) builder.AggBuilder

Rank builds the rank aggregate function.

rank ( args ) WITHIN GROUP ( ORDER BY sorted_args ) → bigint

Computes the rank of the hypothetical row, with gaps; that is, the row number of the first row in its peer group.

func RowNumber added in v0.11.0

func RowNumber() builder.WindowFuncBuilder

RowNumber builds the row_number window function.

row_number () → bigint

Returns the number of the current row within its partition, counting from 1.

func StringAgg

func StringAgg(value, delimiter builder.Exp) builder.AggBuilder

StringAgg builds the string_agg aggregate function.

string_agg ( value text, delimiter text ) → text
string_agg ( value bytea, delimiter bytea ) → bytea

Concatenates the non-null input values into a string. Each value after the first is preceded by the corresponding delimiter (if it's not null).

func StringToArray added in v0.13.0

func StringToArray(text builder.Exp, delim builder.Exp, nullString ...builder.Exp) builder.ExpBase

StringToArray splits string into array elements using supplied delimiter and optional null string.

string_to_array ( text, text [, text ] ) → text[]

func Sum

func Sum(exp builder.Exp) builder.AggBuilder

Sum builds the sum aggregate function.

sum ( T ) → T

Computes the sum of the non-null input values.

func Unnest added in v0.12.0

func Unnest(anyarray builder.Exp, anyarrays ...builder.Exp) builder.FuncBuilder

Unnest builds an unnest functional call.

unnest ( anyarray, anyarray [, ... ] ) → setof anyelement, anyelement [, ... ]

With single argument: Expands an array into a set of rows. The array's elements are read out in storage order. With multiple arguments: 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.

func Upper added in v0.5.1

func Upper(identer builder.Exp) builder.ExpBase

func Xmlagg

func Xmlagg(exp builder.Exp) builder.AggBuilder

Xmlagg builds the xmlagg aggregate function.

xmlagg ( xml ) → xml

Concatenates the non-null XML input values.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL