Skip to content

Commit 837a2e3

Browse files
craig[bot]rafiss
andcommitted
Merge #150777
150777: sql: fix entries for I/O functions for "trigger" and "any" in pg_type r=rafiss a=rafiss The I/O functions for the trigger and any types were removed in 4285c3b and c381b08. Those commits went too far -- these types have `*_in` and `*_out` functions, but not `*_send` and `*_recv`. fixes #146255 Release note (bug fix): Fixed the pg_catalog.pg_type enties for the "any" and "trigger" pseudotypes. Co-authored-by: Rafi Shamim <[email protected]>
2 parents 631d99e + ec547f0 commit 837a2e3

File tree

5 files changed

+42
-28
lines changed

5 files changed

+42
-28
lines changed

pkg/ccl/logictestccl/testdata/logic_test/triggers

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,16 @@ SELECT 1::TRIGGER;
124124
statement error pgcode 0A000 pq: cannot accept a value of type trigger
125125
SELECT NULL:::TRIGGER;
126126

127-
# Triggers should not have a builtin type-conversion function.
128-
statement error pgcode 42883 pq: unknown function: triggerin\(\)
129-
SELECT triggerin(1);
127+
# The builtin type-conversion function should not be usable.
128+
statement error pgcode 0A000 pq: cannot accept a value of type trigger
129+
SELECT trigger_in(1);
130130

131-
statement error pgcode 42883 pq: unknown function: triggerin\(\)
132-
SELECT triggerin(NULL);
131+
# Builtin type conversion function with NULL argument.
132+
# NOTE: this case succeeds because the function is not actually called
133+
# or fully type-checked when it is supplied NULL arguments.
134+
# statement error pgcode 0A000 pq: cannot accept a value of type trigger
135+
statement ok
136+
SELECT trigger_in(NULL);
133137

134138
# ==============================================================================
135139
# Test invalid usage of the TRIGGER datatype in CREATE statements.

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,10 +2193,10 @@ oid typname typinput typoutput typreceive
21932193
2210 _regclass array_in array_out array_recv array_send 0 0 0
21942194
2211 _regtype array_in array_out array_recv array_send 0 0 0
21952195
2249 record record_in record_out record_recv record_send 0 0 0
2196-
2276 any - - - - 0 0 0
2196+
2276 any any_in any_out - - 0 0 0
21972197
2277 anyarray anyarray_in anyarray_out anyarray_recv anyarray_send 0 0 0
21982198
2278 void voidin voidout voidrecv voidsend 0 0 0
2199-
2279 trigger - - - - 0 0 0
2199+
2279 trigger trigger_in trigger_out - - 0 0 0
22002200
2283 anyelement anyelement_in anyelement_out anyelement_recv anyelement_send 0 0 0
22012201
2287 _record array_in array_out array_recv array_send 0 0 0
22022202
2950 uuid uuid_in uuid_out uuid_recv uuid_send 0 0 0

pkg/sql/pg_catalog.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,10 +3581,12 @@ func addPGTypeRow(
35813581
case types.VoidFamily:
35823582
// void does not have an array type.
35833583
case types.TriggerFamily:
3584-
// trigger does not have an array type.
3584+
builtinPrefix = "trigger_"
3585+
// trigger does not have an array type.
35853586
case types.AnyFamily:
3586-
// Any does not have an array type. You may be thinking of AnyElement.
35873587
if typ.Oid() == oid.T_any {
3588+
builtinPrefix = "any_"
3589+
// Any does not have an array type.
35883590
break
35893591
}
35903592
fallthrough

pkg/sql/sem/builtins/fixed_oids.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,10 @@ var builtinOidsArray = []string{
27492749
2786: `citext(jsonpath: jsonpath) -> citext`,
27502750
2787: `citext(box2d: box2d) -> citext`,
27512751
2788: `citext(vector: vector) -> citext`,
2752+
2789: `any_out(any: any) -> bytes`,
2753+
2790: `any_in(input: anyelement) -> any`,
2754+
2791: `trigger_out(trigger: trigger) -> bytes`,
2755+
2792: `trigger_in(input: anyelement) -> trigger`,
27522756
}
27532757

27542758
var builtinOidsBySignature map[string]oid.Oid

pkg/sql/sem/builtins/pg_builtins.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func makeNotUsableFalseBuiltin() builtinDefinition {
6565
// programmatically determine whether or not this underscore is present, hence
6666
// the existence of this map.
6767
var typeBuiltinsHaveUnderscore = map[oid.Oid]struct{}{
68-
// We don't make builtins for T_any because PG's builtins just error but, if we did, they would have underscores.
6968
types.Any.Oid(): {},
7069
types.AnyElement.Oid(): {},
7170
types.AnyArray.Oid(): {},
@@ -84,6 +83,7 @@ var typeBuiltinsHaveUnderscore = map[oid.Oid]struct{}{
8483
oid.T_bit: {},
8584
types.Timestamp.Oid(): {},
8685
types.TimestampTZ.Oid(): {},
86+
types.Trigger.Oid(): {},
8787
types.AnyTuple.Oid(): {},
8888
}
8989

@@ -109,14 +109,6 @@ func init() {
109109
// Make non-array type i/o builtins.
110110
for _, typ := range types.OidToType {
111111
switch typ.Oid() {
112-
case oid.T_any:
113-
// Postgres doesn't have any_send or any_recv. It does have any_in and any_out,
114-
// but they always error, so let's just skip these builtins altogether.
115-
continue
116-
case oid.T_trigger:
117-
// TRIGGER is not valid in any context apart from the return-type of a
118-
// trigger function.
119-
continue
120112
case oid.T_int2vector, oid.T_oidvector:
121113
// Handled separately below.
122114
default:
@@ -292,23 +284,35 @@ func makeTypeIOBuiltin(paramTypes tree.TypeList, returnType *types.T) builtinDef
292284
)
293285
}
294286

295-
// makeTypeIOBuiltins generates the 4 i/o builtins that Postgres implements for
296-
// every type: typein, typeout, typerecv, and typsend. All 4 builtins are no-op,
297-
// and only supported because ORMs sometimes use their names to form a map for
298-
// client-side type encoding and decoding. See issue #12526 for more details.
287+
// makeTypeIOBuiltins generates the i/o builtins that Postgres implements for
288+
// each type. Typically this includes typein, typeout, typerecv, and typsend.
289+
// However, for certain pseudo-types like "any" and "trigger", PostgreSQL only
290+
// has the in/out functions. All builtins are no-op, and only supported because
291+
// ORMs sometimes use their names to form a map for client-side type encoding
292+
// and decoding. See issue #12526 for more details.
299293
func makeTypeIOBuiltins(builtinPrefix string, typ *types.T) map[string]builtinDefinition {
300294
typname := typ.String()
301-
return map[string]builtinDefinition{
302-
builtinPrefix + "send": makeTypeIOBuiltin(tree.ParamTypes{{Name: typname, Typ: typ}}, types.Bytes),
303-
// Note: PG takes type 2281 "internal" for these builtins, which we don't
304-
// provide. We won't implement these functions anyway, so it shouldn't
305-
// matter.
306-
builtinPrefix + "recv": makeTypeIOBuiltin(tree.ParamTypes{{Name: "input", Typ: types.AnyElement}}, typ),
295+
result := map[string]builtinDefinition{
307296
// Note: PG returns 'cstring' for these builtins, but we don't support that.
308297
builtinPrefix + "out": makeTypeIOBuiltin(tree.ParamTypes{{Name: typname, Typ: typ}}, types.Bytes),
309298
// Note: PG takes 'cstring' for these builtins, but we don't support that.
310299
builtinPrefix + "in": makeTypeIOBuiltin(tree.ParamTypes{{Name: "input", Typ: types.AnyElement}}, typ),
311300
}
301+
302+
// PostgreSQL doesn't have send/recv functions for certain pseudo-types.
303+
switch typ.Oid() {
304+
case oid.T_any, oid.T_trigger:
305+
// PostgreSQL has any_in/any_out and trigger_in/trigger_out but not
306+
// any_send/any_recv or trigger_send/trigger_recv.
307+
default:
308+
result[builtinPrefix+"send"] = makeTypeIOBuiltin(tree.ParamTypes{{Name: typname, Typ: typ}}, types.Bytes)
309+
// Note: PG takes type 2281 "internal" for these builtins, which we don't
310+
// provide. We won't implement these functions anyway, so it shouldn't
311+
// matter.
312+
result[builtinPrefix+"recv"] = makeTypeIOBuiltin(tree.ParamTypes{{Name: "input", Typ: types.AnyElement}}, typ)
313+
}
314+
315+
return result
312316
}
313317

314318
// http://doxygen.postgresql.org/pg__wchar_8h.html#a22e0c8b9f59f6e226a5968620b4bb6a9aac3b065b882d3231ba59297524da2f23

0 commit comments

Comments
 (0)