2002-08-22 02:01:51 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pseudotypes.c
|
|
|
|
* Functions for the system pseudo-types.
|
|
|
|
*
|
|
|
|
* A pseudo-type isn't really a type and never has any operations, but
|
|
|
|
* we do need to supply input and output functions to satisfy the links
|
|
|
|
* in the pseudo-type's entry in pg_type. In most cases the functions
|
2002-09-04 22:31:48 +02:00
|
|
|
* just throw an error if invoked. (XXX the error messages here cover
|
2002-08-22 02:01:51 +02:00
|
|
|
* the most common case, but might be confusing in some contexts. Can
|
|
|
|
* we do better?)
|
|
|
|
*
|
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2002-08-22 02:01:51 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2006-02-28 23:37:27 +01:00
|
|
|
* $PostgreSQL: pgsql/src/backend/utils/adt/pseudotypes.c,v 1.16 2006/02/28 22:37:26 tgl Exp $
|
2002-08-22 02:01:51 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2003-05-13 20:03:08 +02:00
|
|
|
#include "libpq/pqformat.h"
|
2002-08-26 19:54:02 +02:00
|
|
|
#include "utils/array.h"
|
2002-08-22 02:01:51 +02:00
|
|
|
#include "utils/builtins.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cstring_in - input routine for pseudo-type CSTRING.
|
2002-08-24 17:00:47 +02:00
|
|
|
*
|
|
|
|
* We might as well allow this to support constructs like "foo_in('blah')".
|
2002-08-22 02:01:51 +02:00
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
cstring_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2002-08-24 17:00:47 +02:00
|
|
|
char *str = PG_GETARG_CSTRING(0);
|
2002-08-22 02:01:51 +02:00
|
|
|
|
2002-08-24 17:00:47 +02:00
|
|
|
PG_RETURN_CSTRING(pstrdup(str));
|
2002-08-22 02:01:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cstring_out - output routine for pseudo-type CSTRING.
|
2002-08-24 17:00:47 +02:00
|
|
|
*
|
|
|
|
* We allow this mainly so that "SELECT some_output_function(...)" does
|
|
|
|
* what the user will expect.
|
2002-08-22 02:01:51 +02:00
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
cstring_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2002-08-24 17:00:47 +02:00
|
|
|
char *str = PG_GETARG_CSTRING(0);
|
2002-08-22 02:01:51 +02:00
|
|
|
|
2002-08-24 17:00:47 +02:00
|
|
|
PG_RETURN_CSTRING(pstrdup(str));
|
2002-08-22 02:01:51 +02:00
|
|
|
}
|
|
|
|
|
2003-05-13 20:03:08 +02:00
|
|
|
/*
|
|
|
|
* cstring_recv - binary input routine for pseudo-type CSTRING.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
cstring_recv(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
|
|
|
char *str;
|
|
|
|
int nbytes;
|
|
|
|
|
|
|
|
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
|
|
|
|
PG_RETURN_CSTRING(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cstring_send - binary output routine for pseudo-type CSTRING.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
cstring_send(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
char *str = PG_GETARG_CSTRING(0);
|
|
|
|
StringInfoData buf;
|
|
|
|
|
|
|
|
pq_begintypsend(&buf);
|
|
|
|
pq_sendtext(&buf, str, strlen(str));
|
|
|
|
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
|
|
|
|
}
|
|
|
|
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* any_in - input routine for pseudo-type ANY.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
any_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2003-07-28 02:09:16 +02:00
|
|
|
errmsg("cannot accept a value of type any")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* any_out - output routine for pseudo-type ANY.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
any_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot display a value of type any")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* anyarray_in - input routine for pseudo-type ANYARRAY.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
anyarray_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2003-07-28 02:09:16 +02:00
|
|
|
errmsg("cannot accept a value of type anyarray")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* anyarray_out - output routine for pseudo-type ANYARRAY.
|
2002-08-26 19:54:02 +02:00
|
|
|
*
|
|
|
|
* We may as well allow this, since array_out will in fact work.
|
2002-08-22 02:01:51 +02:00
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
anyarray_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2002-08-26 19:54:02 +02:00
|
|
|
return array_out(fcinfo);
|
2002-08-22 02:01:51 +02:00
|
|
|
}
|
|
|
|
|
2003-05-13 20:03:08 +02:00
|
|
|
/*
|
|
|
|
* anyarray_recv - binary input routine for pseudo-type ANYARRAY.
|
|
|
|
*
|
|
|
|
* XXX this could actually be made to work, since the incoming array
|
2003-08-04 02:43:34 +02:00
|
|
|
* data will contain the element type OID. Need to think through
|
2003-05-13 20:03:08 +02:00
|
|
|
* type-safety issues before allowing it, however.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
anyarray_recv(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot accept a value of type anyarray")));
|
2003-05-13 20:03:08 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* anyarray_send - binary output routine for pseudo-type ANYARRAY.
|
|
|
|
*
|
|
|
|
* We may as well allow this, since array_send will in fact work.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
anyarray_send(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
return array_send(fcinfo);
|
|
|
|
}
|
|
|
|
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void_in - input routine for pseudo-type VOID.
|
|
|
|
*
|
|
|
|
* We allow this so that PL functions can return VOID without any special
|
2002-09-04 22:31:48 +02:00
|
|
|
* hack in the PL handler. Whatever value the PL thinks it's returning
|
2002-08-22 02:01:51 +02:00
|
|
|
* will just be ignored.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
void_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
PG_RETURN_VOID(); /* you were expecting something different? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* void_out - output routine for pseudo-type VOID.
|
|
|
|
*
|
|
|
|
* We allow this so that "SELECT function_returning_void(...)" works.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
void_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
PG_RETURN_CSTRING(pstrdup(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trigger_in - input routine for pseudo-type TRIGGER.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
trigger_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2003-07-28 02:09:16 +02:00
|
|
|
errmsg("cannot accept a value of type trigger")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trigger_out - output routine for pseudo-type TRIGGER.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
trigger_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot display a value of type trigger")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* language_handler_in - input routine for pseudo-type LANGUAGE_HANDLER.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
language_handler_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2003-07-28 02:09:16 +02:00
|
|
|
errmsg("cannot accept a value of type language_handler")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* language_handler_out - output routine for pseudo-type LANGUAGE_HANDLER.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
language_handler_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot display a value of type language_handler")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* internal_in - input routine for pseudo-type INTERNAL.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
internal_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2003-07-28 02:09:16 +02:00
|
|
|
errmsg("cannot accept a value of type internal")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* internal_out - output routine for pseudo-type INTERNAL.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
internal_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot display a value of type internal")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opaque_in - input routine for pseudo-type OPAQUE.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
opaque_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2003-07-28 02:09:16 +02:00
|
|
|
errmsg("cannot accept a value of type opaque")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opaque_out - output routine for pseudo-type OPAQUE.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
opaque_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot display a value of type opaque")));
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
2003-04-09 01:20:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* anyelement_in - input routine for pseudo-type ANYELEMENT.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
anyelement_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2003-07-28 02:09:16 +02:00
|
|
|
errmsg("cannot accept a value of type anyelement")));
|
2003-04-09 01:20:04 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* anyelement_out - output routine for pseudo-type ANYELEMENT.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
anyelement_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot display a value of type anyelement")));
|
2003-04-09 01:20:04 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
2006-02-28 23:37:27 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* shell_in - input routine for "shell" types (those not yet filled in).
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
shell_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot accept a value of a shell type")));
|
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* shell_out - output routine for "shell" types.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
shell_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("cannot display a value of a shell type")));
|
|
|
|
|
|
|
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
|
|
}
|