diff --git a/docs/generated/sql/functions.md b/docs/generated/sql/functions.md index 44a995cbc69f..969a1d5b7543 100644 --- a/docs/generated/sql/functions.md +++ b/docs/generated/sql/functions.md @@ -3283,6 +3283,8 @@ may increase either contention or retry errors, or both.

Stable obj_description(object_oid: oid, catalog_name: string) → string

Returns the comment for a database object specified by its OID and the name of the containing system catalog. For example, obj_description(123456, ‘pg_class’) would retrieve the comment for the table with OID 123456.

Stable +oidvectortypes(vector: oidvector) → string

Generates a comma seperated string of type names from an oidvector

+
Stable pg_backend_pid() → int

Returns a numerical ID attached to this session. This ID is part of the query cancellation key used by the wire protocol. This function was only added for compatibility, and unlike in Postgres, the returned value does not correspond to a real process ID.

Stable pg_collation_for(str: anyelement) → string

Returns the collation of the argument

diff --git a/pkg/sql/logictest/testdata/logic_test/builtin_function b/pkg/sql/logictest/testdata/logic_test/builtin_function index 966cd754b46d..1cb4db46116a 100644 --- a/pkg/sql/logictest/testdata/logic_test/builtin_function +++ b/pkg/sql/logictest/testdata/logic_test/builtin_function @@ -4037,3 +4037,19 @@ SELECT crdb_internal.merge_aggregated_stmt_metadata(ARRAY[ '{"aMalformedMetadaOb {"appNames": [], "db": [], "distSQLCount": 0, "failedCount": 0, "fingerprintID": "", "formattedQuery": "", "fullScanCount": 0, "implicitTxn": false, "query": "", "querySummary": "", "stmtType": "", "totalCount": 0, "vecCount": 0} subtest end + +# Query `percentile_disc_impl(arg1: float, arg2: bool) -> bool` from pg_proc +query T rowsort +SELECT oidvectortypes(proargtypes) FROM pg_proc WHERE oid=263 +---- +float, bool + +# Query a custom type and function. +statement ok +CREATE TYPE custom_typ AS ENUM ('good', 'bad'); +CREATE OR REPLACE FUNCTION custom_fn(c custom_typ) RETURNS custom_typ AS 'SELECT c' LANGUAGE SQL; + +query T rowsort +SELECT oidvectortypes(proargtypes) FROM pg_proc WHERE proname='custom_fn' +--- +custom_typ diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index bff0204d8db1..6d6283b788e7 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -3993,6 +3993,41 @@ value if you rely on the HLC for accuracy.`, }, ), + "oidvectortypes": makeBuiltin( + tree.FunctionProperties{ + Category: builtinconstants.CategoryCompatibility, + }, + tree.Overload{ + Types: tree.ParamTypes{ + {Name: "vector", Typ: types.OidVector}, + }, + ReturnType: tree.FixedReturnType(types.String), + Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { + var err error + oidVector := args[0].(*tree.DArray) + result := strings.Builder{} + for idx, datum := range oidVector.Array { + oidDatum := datum.(*tree.DOid) + var typ *types.T + if resolvedTyp, ok := types.OidToType[oidDatum.Oid]; ok { + typ = resolvedTyp + } else { + typ, err = evalCtx.Planner.ResolveTypeByOID(ctx, oidDatum.Oid) + if err != nil { + return nil, err + } + } + result.WriteString(typ.Name()) + if idx != len(oidVector.Array)-1 { + result.WriteString(", ") + } + } + return tree.NewDString(result.String()), nil + }, + Info: "Generates a comma seperated string of type names from an oidvector.", + Volatility: volatility.Stable, + }), + "crdb_internal.pb_to_json": makeBuiltin( jsonProps(), func() []tree.Overload { diff --git a/pkg/sql/sem/builtins/fixed_oids.go b/pkg/sql/sem/builtins/fixed_oids.go index 47d98a8c2a7d..b6cb47dd357e 100644 --- a/pkg/sql/sem/builtins/fixed_oids.go +++ b/pkg/sql/sem/builtins/fixed_oids.go @@ -2440,6 +2440,7 @@ var builtinOidsArray = []string{ 2467: `crdb_internal.request_statement_bundle(stmtFingerprint: string, planGist: string, samplingProbability: float, minExecutionLatency: interval, expiresAfter: interval) -> bool`, 2468: `crdb_internal.request_statement_bundle(stmtFingerprint: string, planGist: string, antiPlanGist: bool, samplingProbability: float, minExecutionLatency: interval, expiresAfter: interval) -> bool`, 2469: `crdb_internal.is_system_table_key(raw_key: bytes) -> bool`, + 2470: `oidvectortypes(vector: oidvector) -> string`, } var builtinOidsBySignature map[string]oid.Oid