Skip to content

Commit a5954de

Browse files
committed
Save redundant code for pseudotype I/O functions
Use a macro to generate the in and out functions for pseudotypes that reject all input and output, saving many lines of redundant code. Parameterize the error messages to reduce translatable strings.
1 parent 7f1bcfb commit a5954de

File tree

1 file changed

+45
-301
lines changed

1 file changed

+45
-301
lines changed

src/backend/utils/adt/pseudotypes.c

+45-301
Original file line numberDiff line numberDiff line change
@@ -83,34 +83,6 @@ cstring_send(PG_FUNCTION_ARGS)
8383
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
8484
}
8585

86-
87-
/*
88-
* any_in - input routine for pseudo-type ANY.
89-
*/
90-
Datum
91-
any_in(PG_FUNCTION_ARGS)
92-
{
93-
ereport(ERROR,
94-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
95-
errmsg("cannot accept a value of type any")));
96-
97-
PG_RETURN_VOID(); /* keep compiler quiet */
98-
}
99-
100-
/*
101-
* any_out - output routine for pseudo-type ANY.
102-
*/
103-
Datum
104-
any_out(PG_FUNCTION_ARGS)
105-
{
106-
ereport(ERROR,
107-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
108-
errmsg("cannot display a value of type any")));
109-
110-
PG_RETURN_VOID(); /* keep compiler quiet */
111-
}
112-
113-
11486
/*
11587
* anyarray_in - input routine for pseudo-type ANYARRAY.
11688
*/
@@ -119,7 +91,7 @@ anyarray_in(PG_FUNCTION_ARGS)
11991
{
12092
ereport(ERROR,
12193
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
122-
errmsg("cannot accept a value of type anyarray")));
94+
errmsg("cannot accept a value of type %s", "anyarray")));
12395

12496
PG_RETURN_VOID(); /* keep compiler quiet */
12597
}
@@ -147,7 +119,7 @@ anyarray_recv(PG_FUNCTION_ARGS)
147119
{
148120
ereport(ERROR,
149121
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
150-
errmsg("cannot accept a value of type anyarray")));
122+
errmsg("cannot accept a value of type %s", "anyarray")));
151123

152124
PG_RETURN_VOID(); /* keep compiler quiet */
153125
}
@@ -172,7 +144,7 @@ anyenum_in(PG_FUNCTION_ARGS)
172144
{
173145
ereport(ERROR,
174146
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
175-
errmsg("cannot accept a value of type anyenum")));
147+
errmsg("cannot accept a value of type %s", "anyenum")));
176148

177149
PG_RETURN_VOID(); /* keep compiler quiet */
178150
}
@@ -196,7 +168,7 @@ anyrange_in(PG_FUNCTION_ARGS)
196168
{
197169
ereport(ERROR,
198170
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
199-
errmsg("cannot accept a value of type anyrange")));
171+
errmsg("cannot accept a value of type %s", "anyrange")));
200172

201173
PG_RETURN_VOID(); /* keep compiler quiet */
202174
}
@@ -264,275 +236,6 @@ void_send(PG_FUNCTION_ARGS)
264236
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
265237
}
266238

267-
268-
/*
269-
* trigger_in - input routine for pseudo-type TRIGGER.
270-
*/
271-
Datum
272-
trigger_in(PG_FUNCTION_ARGS)
273-
{
274-
ereport(ERROR,
275-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
276-
errmsg("cannot accept a value of type trigger")));
277-
278-
PG_RETURN_VOID(); /* keep compiler quiet */
279-
}
280-
281-
/*
282-
* trigger_out - output routine for pseudo-type TRIGGER.
283-
*/
284-
Datum
285-
trigger_out(PG_FUNCTION_ARGS)
286-
{
287-
ereport(ERROR,
288-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
289-
errmsg("cannot display a value of type trigger")));
290-
291-
PG_RETURN_VOID(); /* keep compiler quiet */
292-
}
293-
294-
295-
/*
296-
* event_trigger_in - input routine for pseudo-type event_trigger.
297-
*/
298-
Datum
299-
event_trigger_in(PG_FUNCTION_ARGS)
300-
{
301-
ereport(ERROR,
302-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
303-
errmsg("cannot accept a value of type event_trigger")));
304-
305-
PG_RETURN_VOID(); /* keep compiler quiet */
306-
}
307-
308-
/*
309-
* event_trigger_out - output routine for pseudo-type event_trigger.
310-
*/
311-
Datum
312-
event_trigger_out(PG_FUNCTION_ARGS)
313-
{
314-
ereport(ERROR,
315-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
316-
errmsg("cannot display a value of type event_trigger")));
317-
318-
PG_RETURN_VOID(); /* keep compiler quiet */
319-
}
320-
321-
322-
/*
323-
* language_handler_in - input routine for pseudo-type LANGUAGE_HANDLER.
324-
*/
325-
Datum
326-
language_handler_in(PG_FUNCTION_ARGS)
327-
{
328-
ereport(ERROR,
329-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
330-
errmsg("cannot accept a value of type language_handler")));
331-
332-
PG_RETURN_VOID(); /* keep compiler quiet */
333-
}
334-
335-
/*
336-
* language_handler_out - output routine for pseudo-type LANGUAGE_HANDLER.
337-
*/
338-
Datum
339-
language_handler_out(PG_FUNCTION_ARGS)
340-
{
341-
ereport(ERROR,
342-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
343-
errmsg("cannot display a value of type language_handler")));
344-
345-
PG_RETURN_VOID(); /* keep compiler quiet */
346-
}
347-
348-
349-
/*
350-
* fdw_handler_in - input routine for pseudo-type FDW_HANDLER.
351-
*/
352-
Datum
353-
fdw_handler_in(PG_FUNCTION_ARGS)
354-
{
355-
ereport(ERROR,
356-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
357-
errmsg("cannot accept a value of type fdw_handler")));
358-
359-
PG_RETURN_VOID(); /* keep compiler quiet */
360-
}
361-
362-
/*
363-
* fdw_handler_out - output routine for pseudo-type FDW_HANDLER.
364-
*/
365-
Datum
366-
fdw_handler_out(PG_FUNCTION_ARGS)
367-
{
368-
ereport(ERROR,
369-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
370-
errmsg("cannot display a value of type fdw_handler")));
371-
372-
PG_RETURN_VOID(); /* keep compiler quiet */
373-
}
374-
375-
376-
/*
377-
* index_am_handler_in - input routine for pseudo-type INDEX_AM_HANDLER.
378-
*/
379-
Datum
380-
index_am_handler_in(PG_FUNCTION_ARGS)
381-
{
382-
ereport(ERROR,
383-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
384-
errmsg("cannot accept a value of type index_am_handler")));
385-
386-
PG_RETURN_VOID(); /* keep compiler quiet */
387-
}
388-
389-
/*
390-
* index_am_handler_out - output routine for pseudo-type INDEX_AM_HANDLER.
391-
*/
392-
Datum
393-
index_am_handler_out(PG_FUNCTION_ARGS)
394-
{
395-
ereport(ERROR,
396-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
397-
errmsg("cannot display a value of type index_am_handler")));
398-
399-
PG_RETURN_VOID(); /* keep compiler quiet */
400-
}
401-
402-
403-
/*
404-
* tsm_handler_in - input routine for pseudo-type TSM_HANDLER.
405-
*/
406-
Datum
407-
tsm_handler_in(PG_FUNCTION_ARGS)
408-
{
409-
ereport(ERROR,
410-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
411-
errmsg("cannot accept a value of type tsm_handler")));
412-
413-
PG_RETURN_VOID(); /* keep compiler quiet */
414-
}
415-
416-
/*
417-
* tsm_handler_out - output routine for pseudo-type TSM_HANDLER.
418-
*/
419-
Datum
420-
tsm_handler_out(PG_FUNCTION_ARGS)
421-
{
422-
ereport(ERROR,
423-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
424-
errmsg("cannot display a value of type tsm_handler")));
425-
426-
PG_RETURN_VOID(); /* keep compiler quiet */
427-
}
428-
429-
430-
/*
431-
* internal_in - input routine for pseudo-type INTERNAL.
432-
*/
433-
Datum
434-
internal_in(PG_FUNCTION_ARGS)
435-
{
436-
ereport(ERROR,
437-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
438-
errmsg("cannot accept a value of type internal")));
439-
440-
PG_RETURN_VOID(); /* keep compiler quiet */
441-
}
442-
443-
/*
444-
* internal_out - output routine for pseudo-type INTERNAL.
445-
*/
446-
Datum
447-
internal_out(PG_FUNCTION_ARGS)
448-
{
449-
ereport(ERROR,
450-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
451-
errmsg("cannot display a value of type internal")));
452-
453-
PG_RETURN_VOID(); /* keep compiler quiet */
454-
}
455-
456-
457-
/*
458-
* opaque_in - input routine for pseudo-type OPAQUE.
459-
*/
460-
Datum
461-
opaque_in(PG_FUNCTION_ARGS)
462-
{
463-
ereport(ERROR,
464-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
465-
errmsg("cannot accept a value of type opaque")));
466-
467-
PG_RETURN_VOID(); /* keep compiler quiet */
468-
}
469-
470-
/*
471-
* opaque_out - output routine for pseudo-type OPAQUE.
472-
*/
473-
Datum
474-
opaque_out(PG_FUNCTION_ARGS)
475-
{
476-
ereport(ERROR,
477-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
478-
errmsg("cannot display a value of type opaque")));
479-
480-
PG_RETURN_VOID(); /* keep compiler quiet */
481-
}
482-
483-
484-
/*
485-
* anyelement_in - input routine for pseudo-type ANYELEMENT.
486-
*/
487-
Datum
488-
anyelement_in(PG_FUNCTION_ARGS)
489-
{
490-
ereport(ERROR,
491-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
492-
errmsg("cannot accept a value of type anyelement")));
493-
494-
PG_RETURN_VOID(); /* keep compiler quiet */
495-
}
496-
497-
/*
498-
* anyelement_out - output routine for pseudo-type ANYELEMENT.
499-
*/
500-
Datum
501-
anyelement_out(PG_FUNCTION_ARGS)
502-
{
503-
ereport(ERROR,
504-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
505-
errmsg("cannot display a value of type anyelement")));
506-
507-
PG_RETURN_VOID(); /* keep compiler quiet */
508-
}
509-
510-
/*
511-
* anynonarray_in - input routine for pseudo-type ANYNONARRAY.
512-
*/
513-
Datum
514-
anynonarray_in(PG_FUNCTION_ARGS)
515-
{
516-
ereport(ERROR,
517-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
518-
errmsg("cannot accept a value of type anynonarray")));
519-
520-
PG_RETURN_VOID(); /* keep compiler quiet */
521-
}
522-
523-
/*
524-
* anynonarray_out - output routine for pseudo-type ANYNONARRAY.
525-
*/
526-
Datum
527-
anynonarray_out(PG_FUNCTION_ARGS)
528-
{
529-
ereport(ERROR,
530-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
531-
errmsg("cannot display a value of type anynonarray")));
532-
533-
PG_RETURN_VOID(); /* keep compiler quiet */
534-
}
535-
536239
/*
537240
* shell_in - input routine for "shell" types (those not yet filled in).
538241
*/
@@ -674,3 +377,44 @@ pg_ddl_command_send(PG_FUNCTION_ARGS)
674377

675378
PG_RETURN_VOID();
676379
}
380+
381+
382+
/*
383+
* Generate input and output functions for a pseudotype that will reject all
384+
* input and output attempts.
385+
*/
386+
#define PSEUDOTYPE_DUMMY_IO_FUNCS(typname) \
387+
\
388+
Datum \
389+
typname##_in(PG_FUNCTION_ARGS) \
390+
{ \
391+
ereport(ERROR, \
392+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
393+
errmsg("cannot accept a value of type %s", #typname))); \
394+
\
395+
PG_RETURN_VOID(); /* keep compiler quiet */ \
396+
} \
397+
\
398+
Datum \
399+
typname##_out(PG_FUNCTION_ARGS) \
400+
{ \
401+
ereport(ERROR, \
402+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
403+
errmsg("cannot display a value of type %s", #typname))); \
404+
\
405+
PG_RETURN_VOID(); /* keep compiler quiet */ \
406+
} \
407+
\
408+
extern int no_such_variable
409+
410+
PSEUDOTYPE_DUMMY_IO_FUNCS(any);
411+
PSEUDOTYPE_DUMMY_IO_FUNCS(trigger);
412+
PSEUDOTYPE_DUMMY_IO_FUNCS(event_trigger);
413+
PSEUDOTYPE_DUMMY_IO_FUNCS(language_handler);
414+
PSEUDOTYPE_DUMMY_IO_FUNCS(fdw_handler);
415+
PSEUDOTYPE_DUMMY_IO_FUNCS(index_am_handler);
416+
PSEUDOTYPE_DUMMY_IO_FUNCS(tsm_handler);
417+
PSEUDOTYPE_DUMMY_IO_FUNCS(internal);
418+
PSEUDOTYPE_DUMMY_IO_FUNCS(opaque);
419+
PSEUDOTYPE_DUMMY_IO_FUNCS(anyelement);
420+
PSEUDOTYPE_DUMMY_IO_FUNCS(anynonarray);

0 commit comments

Comments
 (0)