diff --git a/docs/generated/sql/functions.md b/docs/generated/sql/functions.md index 2038a9972f81..d3c38de22b31 100644 --- a/docs/generated/sql/functions.md +++ b/docs/generated/sql/functions.md @@ -2910,6 +2910,8 @@ a CockroachDB HLC in decimal form.

Note that uses of this function disable server-side optimizations and may increase either contention or retry errors, or both.

+crdb_internal.active_version() → jsonb

Returns the current active cluster version.

+
crdb_internal.approximate_timestamp(timestamp: decimal) → timestamp

Converts the crdb_internal_mvcc_timestamp column into an approximate timestamp.

crdb_internal.assignment_cast(val: anyelement, type: anyelement) → anyelement

This function is used internally to perform assignment casts during mutations.

diff --git a/docs/generated/swagger/spec.json b/docs/generated/swagger/spec.json index 76b21ce20cef..6e5daf8aa9ea 100644 --- a/docs/generated/swagger/spec.json +++ b/docs/generated/swagger/spec.json @@ -1580,12 +1580,12 @@ "format": "int32", "x-go-name": "Internal" }, - "major_val": { + "major": { "type": "integer", "format": "int32", "x-go-name": "Major" }, - "minor_val": { + "minor": { "type": "integer", "format": "int32", "x-go-name": "Minor" diff --git a/pkg/roachpb/metadata.proto b/pkg/roachpb/metadata.proto index 3e0946762eb1..95ce1e750849 100644 --- a/pkg/roachpb/metadata.proto +++ b/pkg/roachpb/metadata.proto @@ -448,8 +448,8 @@ message Version { // The names "major" and "minor" are reserved in C in // some platforms (e.g. FreeBSD). - optional int32 major_val = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "Major"]; - optional int32 minor_val = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "Minor"]; + optional int32 major_val = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "Major", (gogoproto.jsontag) = "major"]; + optional int32 minor_val = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "Minor", (gogoproto.jsontag) = "minor"]; // Note that patch is a placeholder and will always be zero. optional int32 patch = 3 [(gogoproto.nullable) = false]; // The internal version is used to introduce migrations during the development diff --git a/pkg/sql/logictest/testdata/logic_test/active_version b/pkg/sql/logictest/testdata/logic_test/active_version new file mode 100644 index 000000000000..aae470150897 --- /dev/null +++ b/pkg/sql/logictest/testdata/logic_test/active_version @@ -0,0 +1,14 @@ +# LogicTest: local-v1.1@v1.0-noupgrade + +query T +SELECT crdb_internal.active_version() +---- +{"internal": 0, "major": 1, "minor": 0, "patch": 0} + +statement ok +SET CLUSTER SETTING version = '1.1' + +query T +SELECT crdb_internal.active_version() +---- +{"internal": 0, "major": 1, "minor": 1, "patch": 0} diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index 6b208ed3ce6e..507de992180c 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -4558,6 +4558,28 @@ value if you rely on the HLC for accuracy.`, }, ), + "crdb_internal.active_version": makeBuiltin( + tree.FunctionProperties{Category: categorySystemInfo}, + tree.Overload{ + Types: tree.ArgTypes{}, + ReturnType: tree.FixedReturnType(types.Jsonb), + Fn: func(ctx *tree.EvalContext, _ tree.Datums) (tree.Datum, error) { + activeVersion := ctx.Settings.Version.ActiveVersionOrEmpty(ctx.Context) + jsonStr, err := gojson.Marshal(&activeVersion.Version) + if err != nil { + return nil, err + } + jsonDatum, err := tree.ParseDJSON(string(jsonStr)) + if err != nil { + return nil, err + } + return jsonDatum, nil + }, + Info: "Returns the current active cluster version.", + Volatility: tree.VolatilityVolatile, + }, + ), + "crdb_internal.is_at_least_version": makeBuiltin( tree.FunctionProperties{Category: categorySystemInfo}, tree.Overload{