@@ -65,7 +65,6 @@ func makeNotUsableFalseBuiltin() builtinDefinition {
65
65
// programmatically determine whether or not this underscore is present, hence
66
66
// the existence of this map.
67
67
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.
69
68
types .Any .Oid (): {},
70
69
types .AnyElement .Oid (): {},
71
70
types .AnyArray .Oid (): {},
@@ -84,6 +83,7 @@ var typeBuiltinsHaveUnderscore = map[oid.Oid]struct{}{
84
83
oid .T_bit : {},
85
84
types .Timestamp .Oid (): {},
86
85
types .TimestampTZ .Oid (): {},
86
+ types .Trigger .Oid (): {},
87
87
types .AnyTuple .Oid (): {},
88
88
}
89
89
@@ -109,14 +109,6 @@ func init() {
109
109
// Make non-array type i/o builtins.
110
110
for _ , typ := range types .OidToType {
111
111
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
120
112
case oid .T_int2vector , oid .T_oidvector :
121
113
// Handled separately below.
122
114
default :
@@ -292,23 +284,35 @@ func makeTypeIOBuiltin(paramTypes tree.TypeList, returnType *types.T) builtinDef
292
284
)
293
285
}
294
286
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.
299
293
func makeTypeIOBuiltins (builtinPrefix string , typ * types.T ) map [string ]builtinDefinition {
300
294
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 {
307
296
// Note: PG returns 'cstring' for these builtins, but we don't support that.
308
297
builtinPrefix + "out" : makeTypeIOBuiltin (tree.ParamTypes {{Name : typname , Typ : typ }}, types .Bytes ),
309
298
// Note: PG takes 'cstring' for these builtins, but we don't support that.
310
299
builtinPrefix + "in" : makeTypeIOBuiltin (tree.ParamTypes {{Name : "input" , Typ : types .AnyElement }}, typ ),
311
300
}
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
312
316
}
313
317
314
318
// http://doxygen.postgresql.org/pg__wchar_8h.html#a22e0c8b9f59f6e226a5968620b4bb6a9aac3b065b882d3231ba59297524da2f23
0 commit comments