diff --git a/pkg/sql/sem/builtins/pg_builtins.go b/pkg/sql/sem/builtins/pg_builtins.go index 895ec4a62a40..0370a95d350f 100644 --- a/pkg/sql/sem/builtins/pg_builtins.go +++ b/pkg/sql/sem/builtins/pg_builtins.go @@ -2056,43 +2056,20 @@ SELECT description // _pg_index_position return the column's position in the index // (or NULL if not there). // - // NOTE: this could be defined as a user-defined function, like - // it is in Postgres: + // NOTE: this is defined as a UDF, same as in Postgres: // https://github.com/postgres/postgres/blob/master/src/backend/catalog/information_schema.sql - // - // CREATE FUNCTION _pg_index_position(oid, smallint) RETURNS int - // LANGUAGE sql STRICT STABLE - // BEGIN ATOMIC - // SELECT (ss.a).n FROM - // (SELECT information_schema._pg_expandarray(indkey) AS a - // FROM pg_catalog.pg_index WHERE indexrelid = $1) ss - // WHERE (ss.a).x = $2; - // END; - // "information_schema._pg_index_position": makeBuiltin(defProps(), tree.Overload{ + IsUDF: true, Types: tree.ParamTypes{ {Name: "oid", Typ: types.Oid}, {Name: "col", Typ: types.Int2}, }, ReturnType: tree.FixedReturnType(types.Int), - Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { - r, err := evalCtx.Planner.QueryRowEx( - ctx, "information_schema._pg_index_position", - sessiondata.NoSessionDataOverride, - `SELECT (ss.a).n FROM - (SELECT information_schema._pg_expandarray(indkey) AS a - FROM pg_catalog.pg_index WHERE indexrelid = $1) ss - WHERE (ss.a).x = $2`, - args[0], args[1]) - if err != nil { - return nil, err - } - if len(r) == 0 { - return tree.DNull, nil - } - return r[0], nil - }, + Body: `SELECT (ss.a).n FROM + (SELECT information_schema._pg_expandarray(indkey) AS a + FROM pg_catalog.pg_index WHERE indexrelid = $1) ss + WHERE (ss.a).x = $2`, Info: notUsableInfo, Volatility: volatility.Stable, },