1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-29 23:43:17 +03:00

Tweak the API for per-datatype typmodin functions so that they are passed

an array of strings rather than an array of integers, and allow any simple
constant or identifier to be used in typmods; for example
	create table foo (f1 widget(42,'23skidoo',point));
Of course the typmodin function has still got to pack this info into a
non-negative int32 for storage, but it's still a useful improvement in
flexibility, especially considering that you can do nearly anything if you
are willing to keep the info in a side table.  We can get away with this
change since we have not yet released a version providing user-definable
typmods.  Per discussion.
This commit is contained in:
Tom Lane
2007-06-15 20:56:52 +00:00
parent 839fcc9fd0
commit 23347231a5
16 changed files with 113 additions and 62 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.23 2007/01/05 22:19:40 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.24 2007/06/15 20:56:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -17,6 +17,7 @@
#include "catalog/pg_type.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
@@ -191,16 +192,21 @@ mda_next_tuple(int n, int *curr, const int *span)
}
/*
* ArrayGetTypmods: verify that argument is a 1-D integer array,
* return its length and a pointer to the first contained integer.
* ArrayGetIntegerTypmods: verify that argument is a 1-D cstring array,
* and get the contents converted to integers. Returns a palloc'd array
* and places the length at *n.
*/
int32 *
ArrayGetTypmods(ArrayType *arr, int *n)
ArrayGetIntegerTypmods(ArrayType *arr, int *n)
{
if (ARR_ELEMTYPE(arr) != INT4OID)
int32 *result;
Datum *elem_values;
int i;
if (ARR_ELEMTYPE(arr) != CSTRINGOID)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
errmsg("typmod array must be type integer[]")));
errmsg("typmod array must be type cstring[]")));
if (ARR_NDIM(arr) != 1)
ereport(ERROR,
@@ -212,7 +218,18 @@ ArrayGetTypmods(ArrayType *arr, int *n)
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("typmod array must not contain nulls")));
*n = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
/* hardwired knowledge about cstring's representation details here */
deconstruct_array(arr, CSTRINGOID,
-2, false, 'c',
&elem_values, NULL, n);
return (int32 *) ARR_DATA_PTR(arr);
result = (int32 *) palloc(*n * sizeof(int32));
for (i = 0; i < *n; i++)
result[i] = pg_atoi(DatumGetCString(elem_values[i]),
sizeof(int32), '\0');
pfree(elem_values);
return result;
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.132 2007/06/05 21:31:06 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.133 2007/06/15 20:56:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,7 +53,7 @@ anytime_typmodin(bool istz, ArrayType *ta)
int32 *tl;
int n;
tl = ArrayGetTypmods(ta, &n);
tl = ArrayGetIntegerTypmods(ta, &n);
/*
* we're not too tense about good error message here because grammar

View File

@@ -14,7 +14,7 @@
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.104 2007/06/09 15:52:30 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.105 2007/06/15 20:56:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -547,7 +547,7 @@ numerictypmodin(PG_FUNCTION_ARGS)
int n;
int32 typmod;
tl = ArrayGetTypmods(ta, &n);
tl = ArrayGetIntegerTypmods(ta, &n);
if (n == 2)
{

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.177 2007/06/05 21:31:06 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.178 2007/06/15 20:56:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -64,7 +64,7 @@ anytimestamp_typmodin(bool istz, ArrayType *ta)
int32 *tl;
int n;
tl = ArrayGetTypmods(ta, &n);
tl = ArrayGetIntegerTypmods(ta, &n);
/*
* we're not too tense about good error message here because grammar
@@ -719,7 +719,7 @@ intervaltypmodin(PG_FUNCTION_ARGS)
int n;
int32 typmod;
tl = ArrayGetTypmods(ta, &n);
tl = ArrayGetIntegerTypmods(ta, &n);
/*
* tl[0] - opt_interval

View File

@@ -9,7 +9,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.53 2007/02/27 23:48:09 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.54 2007/06/15 20:56:51 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -32,7 +32,7 @@ anybit_typmodin(ArrayType *ta, const char *typename)
int32 *tl;
int n;
tl = ArrayGetTypmods(ta, &n);
tl = ArrayGetIntegerTypmods(ta, &n);
/*
* we're not too tense about good error message here because grammar

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.123 2007/04/06 04:21:43 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.124 2007/06/15 20:56:51 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -31,7 +31,7 @@ anychar_typmodin(ArrayType *ta, const char *typename)
int32 *tl;
int n;
tl = ArrayGetTypmods(ta, &n);
tl = ArrayGetIntegerTypmods(ta, &n);
/*
* we're not too tense about good error message here because grammar