mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Change typreceive function API so that receive functions get the same
optional arguments as text input functions, ie, typioparam OID and atttypmod. Make all the datatypes that use typmod enforce it the same way in typreceive as they do in typinput. This fixes a problem with failure to enforce length restrictions during COPY FROM BINARY.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.129 2005/07/04 14:38:31 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.130 2005/07/10 21:13:59 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -170,6 +170,10 @@ Datum
|
||||
timestamp_recv(PG_FUNCTION_ARGS)
|
||||
{
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
#ifdef NOT_USED
|
||||
Oid typelem = PG_GETARG_OID(1);
|
||||
#endif
|
||||
int32 typmod = PG_GETARG_INT32(2);
|
||||
Timestamp timestamp;
|
||||
struct pg_tm tt,
|
||||
*tm = &tt;
|
||||
@ -177,7 +181,6 @@ timestamp_recv(PG_FUNCTION_ARGS)
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
timestamp = (Timestamp) pq_getmsgint64(buf);
|
||||
|
||||
#else
|
||||
timestamp = (Timestamp) pq_getmsgfloat8(buf);
|
||||
#endif
|
||||
@ -185,11 +188,13 @@ timestamp_recv(PG_FUNCTION_ARGS)
|
||||
/* rangecheck: see if timestamp_out would like it */
|
||||
if (TIMESTAMP_NOT_FINITE(timestamp))
|
||||
/* ok */ ;
|
||||
else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) !=0)
|
||||
else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
||||
errmsg("timestamp out of range")));
|
||||
|
||||
AdjustTimestampForTypmod(×tamp, typmod);
|
||||
|
||||
PG_RETURN_TIMESTAMP(timestamp);
|
||||
}
|
||||
|
||||
@ -409,6 +414,10 @@ Datum
|
||||
timestamptz_recv(PG_FUNCTION_ARGS)
|
||||
{
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
#ifdef NOT_USED
|
||||
Oid typelem = PG_GETARG_OID(1);
|
||||
#endif
|
||||
int32 typmod = PG_GETARG_INT32(2);
|
||||
TimestampTz timestamp;
|
||||
int tz;
|
||||
struct pg_tm tt,
|
||||
@ -418,7 +427,6 @@ timestamptz_recv(PG_FUNCTION_ARGS)
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
timestamp = (TimestampTz) pq_getmsgint64(buf);
|
||||
|
||||
#else
|
||||
timestamp = (TimestampTz) pq_getmsgfloat8(buf);
|
||||
#endif
|
||||
@ -431,6 +439,8 @@ timestamptz_recv(PG_FUNCTION_ARGS)
|
||||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
||||
errmsg("timestamp out of range")));
|
||||
|
||||
AdjustTimestampForTypmod(×tamp, typmod);
|
||||
|
||||
PG_RETURN_TIMESTAMPTZ(timestamp);
|
||||
}
|
||||
|
||||
@ -526,7 +536,6 @@ interval_in(PG_FUNCTION_ARGS)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
||||
errmsg("interval out of range")));
|
||||
AdjustIntervalForTypmod(result, typmod);
|
||||
break;
|
||||
|
||||
case DTK_INVALID:
|
||||
@ -540,6 +549,8 @@ interval_in(PG_FUNCTION_ARGS)
|
||||
dtype, str);
|
||||
}
|
||||
|
||||
AdjustIntervalForTypmod(result, typmod);
|
||||
|
||||
PG_RETURN_INTERVAL_P(result);
|
||||
}
|
||||
|
||||
@ -573,18 +584,23 @@ Datum
|
||||
interval_recv(PG_FUNCTION_ARGS)
|
||||
{
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
#ifdef NOT_USED
|
||||
Oid typelem = PG_GETARG_OID(1);
|
||||
#endif
|
||||
int32 typmod = PG_GETARG_INT32(2);
|
||||
Interval *interval;
|
||||
|
||||
interval = (Interval *) palloc(sizeof(Interval));
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
interval->time = pq_getmsgint64(buf);
|
||||
|
||||
#else
|
||||
interval->time = pq_getmsgfloat8(buf);
|
||||
#endif
|
||||
interval->month = pq_getmsgint(buf, sizeof(interval->month));
|
||||
|
||||
AdjustIntervalForTypmod(interval, typmod);
|
||||
|
||||
PG_RETURN_INTERVAL_P(interval);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user