mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
Add a bunch of pseudo-types to replace the behavior formerly associated
with OPAQUE, as per recent pghackers discussion. I still want to do some more work on the 'cstring' pseudo-type, but I'm going to commit the bulk of the changes now before the tree starts shifting under me ...
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Makefile for utils/adt
|
||||
#
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.52 2002/08/17 13:04:15 momjian Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.53 2002/08/22 00:01:43 tgl Exp $
|
||||
#
|
||||
|
||||
subdir = src/backend/utils/adt
|
||||
@@ -19,7 +19,7 @@ OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o \
|
||||
date.o datetime.o datum.o float.o format_type.o \
|
||||
geo_ops.o geo_selfuncs.o int.o int8.o like.o lockfuncs.o \
|
||||
misc.o nabstime.o name.o not_in.o numeric.o numutils.o \
|
||||
oid.o oracle_compat.o \
|
||||
oid.o oracle_compat.o pseudotypes.o \
|
||||
regexp.o regproc.o ruleutils.o selfuncs.o sets.o \
|
||||
tid.o timestamp.o varbit.o varchar.o varlena.o version.o \
|
||||
network.o mac.o inet_net_ntop.o inet_net_pton.o \
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.51 2002/06/20 20:29:37 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.52 2002/08/22 00:01:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -144,59 +144,6 @@ int2vectoreq(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(memcmp(arg1, arg2, INDEX_MAX_KEYS * sizeof(int16)) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Type int44 has no real-world use, but the regression tests use it.
|
||||
* It's a four-element vector of int4's.
|
||||
*/
|
||||
|
||||
/*
|
||||
* int44in - converts "num num ..." to internal form
|
||||
*
|
||||
* Note: Fills any missing positions with zeroes.
|
||||
*/
|
||||
Datum
|
||||
int44in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *input_string = PG_GETARG_CSTRING(0);
|
||||
int32 *result = (int32 *) palloc(4 * sizeof(int32));
|
||||
int i;
|
||||
|
||||
i = sscanf(input_string,
|
||||
"%d, %d, %d, %d",
|
||||
&result[0],
|
||||
&result[1],
|
||||
&result[2],
|
||||
&result[3]);
|
||||
while (i < 4)
|
||||
result[i++] = 0;
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* int44out - converts internal form to "num num ..."
|
||||
*/
|
||||
Datum
|
||||
int44out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
|
||||
char *result = (char *) palloc(16 * 4); /* Allow 14 digits +
|
||||
* sign */
|
||||
int i;
|
||||
char *walk;
|
||||
|
||||
walk = result;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
pg_ltoa(an_array[i], walk);
|
||||
while (*++walk != '\0')
|
||||
;
|
||||
*walk++ = ' ';
|
||||
}
|
||||
*--walk = '\0';
|
||||
PG_RETURN_CSTRING(result);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* PUBLIC ROUTINES *
|
||||
|
||||
234
src/backend/utils/adt/pseudotypes.c
Normal file
234
src/backend/utils/adt/pseudotypes.c
Normal file
@@ -0,0 +1,234 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* 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
|
||||
* just throw an error if invoked. (XXX the error messages here cover
|
||||
* the most common case, but might be confusing in some contexts. Can
|
||||
* we do better?)
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.1 2002/08/22 00:01:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
||||
/*
|
||||
* record_in - input routine for pseudo-type RECORD.
|
||||
*/
|
||||
Datum
|
||||
record_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "RECORD");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* record_out - output routine for pseudo-type RECORD.
|
||||
*/
|
||||
Datum
|
||||
record_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "RECORD");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* cstring_in - input routine for pseudo-type CSTRING.
|
||||
*/
|
||||
Datum
|
||||
cstring_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "CSTRING");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* cstring_out - output routine for pseudo-type CSTRING.
|
||||
*/
|
||||
Datum
|
||||
cstring_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "CSTRING");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* any_in - input routine for pseudo-type ANY.
|
||||
*/
|
||||
Datum
|
||||
any_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "ANY");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* any_out - output routine for pseudo-type ANY.
|
||||
*/
|
||||
Datum
|
||||
any_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "ANY");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* anyarray_in - input routine for pseudo-type ANYARRAY.
|
||||
*/
|
||||
Datum
|
||||
anyarray_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "ANYARRAY");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* anyarray_out - output routine for pseudo-type ANYARRAY.
|
||||
*/
|
||||
Datum
|
||||
anyarray_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "ANYARRAY");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* void_in - input routine for pseudo-type VOID.
|
||||
*
|
||||
* We allow this so that PL functions can return VOID without any special
|
||||
* hack in the PL handler. Whatever value the PL thinks it's returning
|
||||
* 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)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "TRIGGER");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* trigger_out - output routine for pseudo-type TRIGGER.
|
||||
*/
|
||||
Datum
|
||||
trigger_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "TRIGGER");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* language_handler_in - input routine for pseudo-type LANGUAGE_HANDLER.
|
||||
*/
|
||||
Datum
|
||||
language_handler_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "LANGUAGE_HANDLER");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* language_handler_out - output routine for pseudo-type LANGUAGE_HANDLER.
|
||||
*/
|
||||
Datum
|
||||
language_handler_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "LANGUAGE_HANDLER");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* internal_in - input routine for pseudo-type INTERNAL.
|
||||
*/
|
||||
Datum
|
||||
internal_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "INTERNAL");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* internal_out - output routine for pseudo-type INTERNAL.
|
||||
*/
|
||||
Datum
|
||||
internal_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "INTERNAL");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* opaque_in - input routine for pseudo-type OPAQUE.
|
||||
*/
|
||||
Datum
|
||||
opaque_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot accept a constant of type %s", "OPAQUE");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* opaque_out - output routine for pseudo-type OPAQUE.
|
||||
*/
|
||||
Datum
|
||||
opaque_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
elog(ERROR, "Cannot display a value of type %s", "OPAQUE");
|
||||
|
||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.72 2002/07/29 22:14:11 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.73 2002/08/22 00:01:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "utils/syscache.h"
|
||||
|
||||
static void parseNameAndArgTypes(const char *string, const char *caller,
|
||||
const char *type0_spelling,
|
||||
bool allowNone,
|
||||
List **names, int *nargs, Oid *argtypes);
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ regprocedurein(PG_FUNCTION_ARGS)
|
||||
* datatype cannot be used for any system column that needs to receive
|
||||
* data during bootstrap.
|
||||
*/
|
||||
parseNameAndArgTypes(pro_name_or_oid, "regprocedurein", "opaque",
|
||||
parseNameAndArgTypes(pro_name_or_oid, "regprocedurein", false,
|
||||
&names, &nargs, argtypes);
|
||||
|
||||
clist = FuncnameGetCandidates(names, nargs);
|
||||
@@ -325,10 +325,7 @@ format_procedure(Oid procedure_oid)
|
||||
|
||||
if (i > 0)
|
||||
appendStringInfoChar(&buf, ',');
|
||||
if (OidIsValid(thisargtype))
|
||||
appendStringInfo(&buf, "%s", format_type_be(thisargtype));
|
||||
else
|
||||
appendStringInfo(&buf, "opaque");
|
||||
appendStringInfo(&buf, "%s", format_type_be(thisargtype));
|
||||
}
|
||||
appendStringInfoChar(&buf, ')');
|
||||
|
||||
@@ -584,7 +581,7 @@ regoperatorin(PG_FUNCTION_ARGS)
|
||||
* datatype cannot be used for any system column that needs to receive
|
||||
* data during bootstrap.
|
||||
*/
|
||||
parseNameAndArgTypes(opr_name_or_oid, "regoperatorin", "none",
|
||||
parseNameAndArgTypes(opr_name_or_oid, "regoperatorin", true,
|
||||
&names, &nargs, argtypes);
|
||||
if (nargs == 1)
|
||||
elog(ERROR, "regoperatorin: use NONE to denote the missing argument of a unary operator");
|
||||
@@ -1036,12 +1033,12 @@ stringToQualifiedNameList(const char *string, const char *caller)
|
||||
* the argtypes array should be of size FUNC_MAX_ARGS). The function or
|
||||
* operator name is returned to *names as a List of Strings.
|
||||
*
|
||||
* If type0_spelling is not NULL, it is a name to be accepted as a
|
||||
* placeholder for OID 0.
|
||||
* If allowNone is TRUE, accept "NONE" and return it as InvalidOid (this is
|
||||
* for unary operators).
|
||||
*/
|
||||
static void
|
||||
parseNameAndArgTypes(const char *string, const char *caller,
|
||||
const char *type0_spelling,
|
||||
bool allowNone,
|
||||
List **names, int *nargs, Oid *argtypes)
|
||||
{
|
||||
char *rawname;
|
||||
@@ -1147,9 +1144,9 @@ parseNameAndArgTypes(const char *string, const char *caller,
|
||||
*ptr2 = '\0';
|
||||
}
|
||||
|
||||
if (type0_spelling && strcasecmp(typename, type0_spelling) == 0)
|
||||
if (allowNone && strcasecmp(typename, "none") == 0)
|
||||
{
|
||||
/* Special case for OPAQUE or NONE */
|
||||
/* Special case for NONE */
|
||||
typeid = InvalidOid;
|
||||
typmod = -1;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.112 2002/06/20 20:29:38 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.113 2002/08/22 00:01:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -53,7 +53,7 @@
|
||||
*
|
||||
* This is represented at the SQL level (in pg_proc) as
|
||||
*
|
||||
* float8 oprrest (opaque, oid, opaque, int4);
|
||||
* float8 oprrest (internal, oid, internal, int4);
|
||||
*
|
||||
* The call convention for a join estimator (oprjoin function) is similar
|
||||
* except that varRelid is not needed:
|
||||
@@ -62,7 +62,7 @@
|
||||
* Oid operator,
|
||||
* List *args);
|
||||
*
|
||||
* float8 oprjoin (opaque, oid, opaque);
|
||||
* float8 oprjoin (internal, oid, internal);
|
||||
*----------
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user