1998-05-10 01:31:34 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* parse_coerce.c
|
2000-02-20 22:32:16 +01:00
|
|
|
* handle type coercions/conversions for parser
|
1998-05-10 01:31:34 +02:00
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1998-05-10 01:31:34 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2002-11-25 22:29:42 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.87 2002/11/25 21:29:41 tgl Exp $
|
1998-05-10 01:31:34 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2002-11-15 03:50:21 +01:00
|
|
|
#include "access/genam.h"
|
|
|
|
#include "access/heapam.h"
|
|
|
|
#include "catalog/catname.h"
|
|
|
|
#include "catalog/indexing.h"
|
2002-07-19 01:11:32 +02:00
|
|
|
#include "catalog/pg_cast.h"
|
2002-11-15 03:50:21 +01:00
|
|
|
#include "catalog/pg_constraint.h"
|
2000-03-19 01:15:39 +01:00
|
|
|
#include "catalog/pg_proc.h"
|
2002-03-20 20:45:13 +01:00
|
|
|
#include "nodes/makefuncs.h"
|
1999-10-03 01:29:19 +02:00
|
|
|
#include "optimizer/clauses.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "parser/parse_coerce.h"
|
|
|
|
#include "parser/parse_expr.h"
|
1999-06-18 00:21:41 +02:00
|
|
|
#include "parser/parse_func.h"
|
2000-06-15 05:33:12 +02:00
|
|
|
#include "parser/parse_type.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "utils/builtins.h"
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
#include "utils/fmgroids.h"
|
2002-03-20 20:45:13 +01:00
|
|
|
#include "utils/lsyscache.h"
|
1998-05-10 01:31:34 +02:00
|
|
|
#include "utils/syscache.h"
|
|
|
|
|
2002-03-20 20:45:13 +01:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
static Node *coerce_type_typmod(Node *node,
|
|
|
|
Oid targetTypeId, int32 targetTypMod,
|
|
|
|
CoercionForm cformat);
|
1999-05-25 18:15:34 +02:00
|
|
|
static Oid PreferredType(CATEGORY category, Oid type);
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
static Node *build_func_call(Oid funcid, Oid rettype, List *args,
|
|
|
|
CoercionForm fformat);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* coerce_to_target_type()
|
|
|
|
* Convert an expression to a target type and typmod.
|
|
|
|
*
|
|
|
|
* This is the general-purpose entry point for arbitrary type coercion
|
|
|
|
* operations. Direct use of the component operations can_coerce_type,
|
|
|
|
* coerce_type, and coerce_type_typmod should be restricted to special
|
|
|
|
* cases (eg, when the conversion is expected to succeed).
|
|
|
|
*
|
|
|
|
* Returns the possibly-transformed expression tree, or NULL if the type
|
|
|
|
* conversion is not possible. (We do this, rather than elog'ing directly,
|
|
|
|
* so that callers can generate custom error messages indicating context.)
|
|
|
|
*
|
|
|
|
* expr - input expression tree (already transformed by transformExpr)
|
|
|
|
* exprtype - result type of expr
|
|
|
|
* targettype - desired result type
|
|
|
|
* targettypmod - desired result typmod
|
|
|
|
* ccontext, cformat - context indicators to control coercions
|
|
|
|
*/
|
|
|
|
Node *
|
|
|
|
coerce_to_target_type(Node *expr, Oid exprtype,
|
|
|
|
Oid targettype, int32 targettypmod,
|
|
|
|
CoercionContext ccontext,
|
|
|
|
CoercionForm cformat)
|
|
|
|
{
|
|
|
|
if (can_coerce_type(1, &exprtype, &targettype, ccontext))
|
|
|
|
expr = coerce_type(expr, exprtype, targettype,
|
|
|
|
ccontext, cformat);
|
|
|
|
/*
|
|
|
|
* String hacks to get transparent conversions for char and varchar:
|
|
|
|
* if a coercion to text is available, use it for forced coercions to
|
|
|
|
* char(n) or varchar(n).
|
|
|
|
*
|
|
|
|
* This is pretty grotty, but seems easier to maintain than providing
|
|
|
|
* entries in pg_cast that parallel all the ones for text.
|
|
|
|
*/
|
|
|
|
else if (ccontext >= COERCION_ASSIGNMENT &&
|
|
|
|
(targettype == BPCHAROID || targettype == VARCHAROID))
|
|
|
|
{
|
|
|
|
Oid text_id = TEXTOID;
|
|
|
|
|
|
|
|
if (can_coerce_type(1, &exprtype, &text_id, ccontext))
|
|
|
|
{
|
|
|
|
expr = coerce_type(expr, exprtype, text_id,
|
|
|
|
ccontext, cformat);
|
|
|
|
/* Need a RelabelType if no typmod coercion is performed */
|
|
|
|
if (targettypmod < 0)
|
|
|
|
expr = (Node *) makeRelabelType(expr, targettype, -1,
|
|
|
|
cformat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
expr = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
expr = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the target is a fixed-length type, it may need a length coercion
|
|
|
|
* as well as a type coercion.
|
|
|
|
*/
|
|
|
|
if (expr != NULL)
|
|
|
|
expr = coerce_type_typmod(expr, targettype, targettypmod, cformat);
|
|
|
|
|
|
|
|
return expr;
|
|
|
|
}
|
2002-09-01 00:10:48 +02:00
|
|
|
|
1998-05-10 01:31:34 +02:00
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
/*
|
|
|
|
* coerce_type()
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* Convert an expression to a different type.
|
2002-09-01 04:27:32 +02:00
|
|
|
*
|
|
|
|
* The caller should already have determined that the coercion is possible;
|
|
|
|
* see can_coerce_type.
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
*
|
|
|
|
* No coercion to a typmod (length) is performed here. The caller must
|
|
|
|
* call coerce_type_typmod as well, if a typmod constraint is wanted.
|
|
|
|
* (But if the target type is a domain, it may internally contain a
|
|
|
|
* typmod constraint, which will be applied inside coerce_type_constraints.)
|
1998-05-10 01:31:34 +02:00
|
|
|
*/
|
|
|
|
Node *
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
coerce_type(Node *node, Oid inputTypeId, Oid targetTypeId,
|
|
|
|
CoercionContext ccontext, CoercionForm cformat)
|
1998-05-10 01:31:34 +02:00
|
|
|
{
|
2000-02-20 22:32:16 +01:00
|
|
|
Node *result;
|
2002-09-01 04:27:32 +02:00
|
|
|
Oid funcId;
|
1998-05-10 01:31:34 +02:00
|
|
|
|
2000-03-23 08:36:03 +01:00
|
|
|
if (targetTypeId == inputTypeId ||
|
|
|
|
node == NULL)
|
1999-08-05 04:33:54 +02:00
|
|
|
{
|
2002-09-01 00:10:48 +02:00
|
|
|
/* no conversion needed */
|
1998-05-10 01:31:34 +02:00
|
|
|
result = node;
|
1999-08-05 04:33:54 +02:00
|
|
|
}
|
|
|
|
else if (inputTypeId == UNKNOWNOID && IsA(node, Const))
|
|
|
|
{
|
1999-10-03 01:29:19 +02:00
|
|
|
/*
|
|
|
|
* Input is a string constant with previously undetermined type.
|
2000-04-12 19:17:23 +02:00
|
|
|
* Apply the target type's typinput function to it to produce a
|
|
|
|
* constant of the target type.
|
1999-08-05 04:33:54 +02:00
|
|
|
*
|
|
|
|
* NOTE: this case cannot be folded together with the other
|
|
|
|
* constant-input case, since the typinput function does not
|
2000-04-12 19:17:23 +02:00
|
|
|
* necessarily behave the same as a type conversion function. For
|
|
|
|
* example, int4's typinput function will reject "1.2", whereas
|
|
|
|
* float-to-int type conversion will round to integer.
|
1999-10-03 01:29:19 +02:00
|
|
|
*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* XXX if the typinput function is not immutable, we really ought to
|
2000-04-12 19:17:23 +02:00
|
|
|
* postpone evaluation of the function call until runtime. But
|
|
|
|
* there is no way to represent a typinput function call as an
|
2002-09-04 22:31:48 +02:00
|
|
|
* expression tree, because C-string values are not Datums. (XXX
|
|
|
|
* This *is* possible as of 7.3, do we want to do it?)
|
1998-09-01 06:40:42 +02:00
|
|
|
*/
|
1999-08-05 04:33:54 +02:00
|
|
|
Const *con = (Const *) node;
|
1999-08-24 02:09:56 +02:00
|
|
|
Const *newcon = makeNode(Const);
|
1999-08-05 04:33:54 +02:00
|
|
|
Type targetType = typeidType(targetTypeId);
|
2002-09-01 00:10:48 +02:00
|
|
|
char targetTyptype = typeTypType(targetType);
|
1999-08-05 04:33:54 +02:00
|
|
|
|
1999-08-24 02:09:56 +02:00
|
|
|
newcon->consttype = targetTypeId;
|
|
|
|
newcon->constlen = typeLen(targetType);
|
|
|
|
newcon->constbyval = typeByVal(targetType);
|
|
|
|
newcon->constisnull = con->constisnull;
|
1999-08-05 04:33:54 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!con->constisnull)
|
1999-08-24 02:09:56 +02:00
|
|
|
{
|
2002-04-25 04:56:56 +02:00
|
|
|
char *val = DatumGetCString(DirectFunctionCall1(unknownout,
|
2001-03-22 05:01:46 +01:00
|
|
|
con->constvalue));
|
2002-09-01 00:10:48 +02:00
|
|
|
|
|
|
|
/*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* We pass typmod -1 to the input routine, primarily because
|
|
|
|
* existing input routines follow implicit-coercion semantics
|
|
|
|
* for length checks, which is not always what we want here.
|
|
|
|
* Any length constraint will be applied later by our caller.
|
|
|
|
*
|
|
|
|
* Note that we call stringTypeDatum using the domain's pg_type
|
|
|
|
* row, if it's a domain. This works because the domain row has
|
|
|
|
* the same typinput and typelem as the base type --- ugly...
|
2002-09-01 00:10:48 +02:00
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
newcon->constvalue = stringTypeDatum(targetType, val, -1);
|
1999-08-24 02:09:56 +02:00
|
|
|
pfree(val);
|
|
|
|
}
|
1998-05-10 01:31:34 +02:00
|
|
|
|
1999-08-24 02:09:56 +02:00
|
|
|
result = (Node *) newcon;
|
2002-09-01 00:10:48 +02:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/* If target is a domain, apply constraints. */
|
2002-09-01 00:10:48 +02:00
|
|
|
if (targetTyptype == 'd')
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
{
|
|
|
|
result = coerce_type_constraints(result, targetTypeId,
|
|
|
|
cformat);
|
|
|
|
/* We might now need a RelabelType. */
|
|
|
|
if (exprType(result) != targetTypeId)
|
|
|
|
result = (Node *) makeRelabelType(result, targetTypeId, -1,
|
|
|
|
cformat);
|
|
|
|
}
|
2002-09-01 00:10:48 +02:00
|
|
|
|
|
|
|
ReleaseSysCache(targetType);
|
1999-08-05 04:33:54 +02:00
|
|
|
}
|
2002-08-22 02:01:51 +02:00
|
|
|
else if (targetTypeId == ANYOID ||
|
|
|
|
targetTypeId == ANYARRAYOID)
|
|
|
|
{
|
|
|
|
/* assume can_coerce_type verified that implicit coercion is okay */
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/* NB: we do NOT want a RelabelType here */
|
2002-08-22 02:01:51 +02:00
|
|
|
result = node;
|
|
|
|
}
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
else if (find_coercion_pathway(targetTypeId, inputTypeId, ccontext,
|
2002-09-01 04:27:32 +02:00
|
|
|
&funcId))
|
2000-02-20 22:32:16 +01:00
|
|
|
{
|
2002-09-01 04:27:32 +02:00
|
|
|
if (OidIsValid(funcId))
|
|
|
|
{
|
|
|
|
/*
|
2002-09-04 22:31:48 +02:00
|
|
|
* Generate an expression tree representing run-time
|
|
|
|
* application of the conversion function. If we are dealing
|
|
|
|
* with a domain target type, the conversion function will
|
|
|
|
* yield the base type.
|
2002-09-01 04:27:32 +02:00
|
|
|
*/
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid baseTypeId = getBaseType(targetTypeId);
|
2002-09-01 04:27:32 +02:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
result = build_func_call(funcId, baseTypeId, makeList1(node),
|
|
|
|
cformat);
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If domain, test against domain constraints and relabel with
|
|
|
|
* domain type ID
|
|
|
|
*/
|
|
|
|
if (targetTypeId != baseTypeId)
|
|
|
|
{
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
result = coerce_type_constraints(result, targetTypeId,
|
|
|
|
cformat);
|
|
|
|
result = (Node *) makeRelabelType(result, targetTypeId, -1,
|
|
|
|
cformat);
|
2002-09-01 04:27:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-04 22:31:48 +02:00
|
|
|
* If the input is a constant, apply the type conversion
|
|
|
|
* function now instead of delaying to runtime. (We could, of
|
|
|
|
* course, just leave this to be done during
|
|
|
|
* planning/optimization; but it's a very frequent special
|
|
|
|
* case, and we save cycles in the rewriter if we fold the
|
|
|
|
* expression now.)
|
2002-09-01 04:27:32 +02:00
|
|
|
*
|
|
|
|
* Note that no folding will occur if the conversion function is
|
|
|
|
* not marked 'immutable'.
|
|
|
|
*
|
|
|
|
* HACK: if constant is NULL, don't fold it here. This is needed
|
|
|
|
* by make_subplan(), which calls this routine on placeholder
|
2002-09-04 22:31:48 +02:00
|
|
|
* Const nodes that mustn't be collapsed. (It'd be a lot
|
|
|
|
* cleaner to make a separate node type for that purpose...)
|
2002-09-01 04:27:32 +02:00
|
|
|
*/
|
|
|
|
if (IsA(node, Const) &&
|
|
|
|
!((Const *) node)->constisnull)
|
|
|
|
result = eval_const_expressions(result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2002-09-04 22:31:48 +02:00
|
|
|
* We don't need to do a physical conversion, but we do need
|
|
|
|
* to attach a RelabelType node so that the expression will be
|
|
|
|
* seen to have the intended type when inspected by
|
|
|
|
* higher-level code.
|
2002-09-01 04:27:32 +02:00
|
|
|
*
|
|
|
|
* Also, domains may have value restrictions beyond the base type
|
|
|
|
* that must be accounted for.
|
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
result = coerce_type_constraints(node, targetTypeId,
|
|
|
|
cformat);
|
2002-09-04 22:31:48 +02:00
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
/*
|
|
|
|
* XXX could we label result with exprTypmod(node) instead of
|
2002-09-04 22:31:48 +02:00
|
|
|
* default -1 typmod, to save a possible length-coercion
|
|
|
|
* later? Would work if both types have same interpretation of
|
|
|
|
* typmod, which is likely but not certain (wrong if target is
|
|
|
|
* a domain, in any case).
|
2002-09-01 04:27:32 +02:00
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
result = (Node *) makeRelabelType(result, targetTypeId, -1,
|
|
|
|
cformat);
|
2002-09-01 04:27:32 +02:00
|
|
|
}
|
2000-02-20 22:32:16 +01:00
|
|
|
}
|
2000-03-16 07:35:07 +01:00
|
|
|
else if (typeInheritsFrom(inputTypeId, targetTypeId))
|
|
|
|
{
|
2002-03-20 20:45:13 +01:00
|
|
|
/*
|
2002-09-04 22:31:48 +02:00
|
|
|
* Input class type is a subclass of target, so nothing to do ---
|
|
|
|
* except relabel the type. This is binary compatibility for
|
|
|
|
* complex types.
|
2002-03-20 20:45:13 +01:00
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
result = (Node *) makeRelabelType(node, targetTypeId, -1,
|
|
|
|
cformat);
|
2000-03-16 07:35:07 +01:00
|
|
|
}
|
1999-08-05 04:33:54 +02:00
|
|
|
else
|
|
|
|
{
|
2002-09-01 04:27:32 +02:00
|
|
|
/* If we get here, caller blew it */
|
|
|
|
elog(ERROR, "coerce_type: no conversion function from %s to %s",
|
|
|
|
format_type_be(inputTypeId), format_type_be(targetTypeId));
|
|
|
|
result = NULL; /* keep compiler quiet */
|
1998-05-10 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
1999-05-22 06:12:29 +02:00
|
|
|
}
|
1998-05-10 01:31:34 +02:00
|
|
|
|
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
/*
|
|
|
|
* can_coerce_type()
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* Can input_typeids be coerced to target_typeids?
|
2002-04-11 22:00:18 +02:00
|
|
|
*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* We must be told the context (CAST construct, assignment, implicit coercion)
|
|
|
|
* as this determines the set of available casts.
|
1998-05-10 01:31:34 +02:00
|
|
|
*/
|
|
|
|
bool
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
can_coerce_type(int nargs, Oid *input_typeids, Oid *target_typeids,
|
|
|
|
CoercionContext ccontext)
|
1998-05-10 01:31:34 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* run through argument list... */
|
|
|
|
for (i = 0; i < nargs; i++)
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
Oid inputTypeId = input_typeids[i];
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
Oid targetTypeId = target_typeids[i];
|
2002-03-20 20:45:13 +01:00
|
|
|
Oid funcId;
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2000-03-16 07:35:07 +01:00
|
|
|
/* no problem if same type */
|
|
|
|
if (inputTypeId == targetTypeId)
|
|
|
|
continue;
|
1998-05-10 01:31:34 +02:00
|
|
|
|
2002-08-22 02:01:51 +02:00
|
|
|
/* don't choke on references to no-longer-existing types */
|
|
|
|
if (!typeidIsValid(inputTypeId))
|
2000-03-16 07:35:07 +01:00
|
|
|
return false;
|
2002-08-22 02:01:51 +02:00
|
|
|
if (!typeidIsValid(targetTypeId))
|
2000-03-16 07:35:07 +01:00
|
|
|
return false;
|
1999-05-25 18:15:34 +02:00
|
|
|
|
2000-03-16 07:35:07 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* If input is an untyped string constant, assume we can convert
|
|
|
|
* it to anything except a class type.
|
2000-03-16 07:35:07 +01:00
|
|
|
*/
|
|
|
|
if (inputTypeId == UNKNOWNOID)
|
|
|
|
{
|
|
|
|
if (ISCOMPLEX(targetTypeId))
|
1998-05-10 01:31:34 +02:00
|
|
|
return false;
|
2000-03-16 07:35:07 +01:00
|
|
|
continue;
|
1998-05-10 01:31:34 +02:00
|
|
|
}
|
2000-03-16 07:35:07 +01:00
|
|
|
|
2002-08-22 02:01:51 +02:00
|
|
|
/* accept if target is ANY */
|
|
|
|
if (targetTypeId == ANYOID)
|
|
|
|
continue;
|
|
|
|
|
2002-09-04 22:31:48 +02:00
|
|
|
/*
|
|
|
|
* if target is ANYARRAY and source is a varlena array type,
|
|
|
|
* accept
|
|
|
|
*/
|
2002-08-22 02:01:51 +02:00
|
|
|
if (targetTypeId == ANYARRAYOID)
|
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid typOutput;
|
|
|
|
Oid typElem;
|
|
|
|
bool typIsVarlena;
|
2002-08-22 02:01:51 +02:00
|
|
|
|
|
|
|
if (getTypeOutputInfo(inputTypeId, &typOutput, &typElem,
|
|
|
|
&typIsVarlena))
|
|
|
|
{
|
|
|
|
if (OidIsValid(typElem) && typIsVarlena)
|
|
|
|
continue;
|
|
|
|
}
|
2002-09-04 22:31:48 +02:00
|
|
|
|
2002-08-22 02:01:51 +02:00
|
|
|
/*
|
2002-09-04 22:31:48 +02:00
|
|
|
* Otherwise reject; this assumes there are no explicit
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* coercion paths to ANYARRAY. If we don't reject then
|
2002-09-04 22:31:48 +02:00
|
|
|
* parse_coerce would have to repeat the above test.
|
2002-08-22 02:01:51 +02:00
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-01 04:27:32 +02:00
|
|
|
* If pg_cast shows that we can coerce, accept. This test now
|
|
|
|
* covers both binary-compatible and coercion-function cases.
|
2002-08-22 02:01:51 +02:00
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (find_coercion_pathway(targetTypeId, inputTypeId, ccontext,
|
2002-09-01 04:27:32 +02:00
|
|
|
&funcId))
|
2002-08-22 02:01:51 +02:00
|
|
|
continue;
|
|
|
|
|
2000-03-16 07:35:07 +01:00
|
|
|
/*
|
2002-09-01 04:27:32 +02:00
|
|
|
* If input is a class type that inherits from target, accept
|
2000-03-16 07:35:07 +01:00
|
|
|
*/
|
|
|
|
if (typeInheritsFrom(inputTypeId, targetTypeId))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2002-09-01 04:27:32 +02:00
|
|
|
* Else, cannot coerce at this argument position
|
2000-03-16 07:35:07 +01:00
|
|
|
*/
|
2002-09-01 04:27:32 +02:00
|
|
|
return false;
|
1998-05-10 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
1999-05-22 06:12:29 +02:00
|
|
|
}
|
1998-05-10 01:31:34 +02:00
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create an expression tree to enforce the constraints (if any)
|
2002-09-04 22:31:48 +02:00
|
|
|
* that should be applied by the type. Currently this is only
|
2002-09-01 04:27:32 +02:00
|
|
|
* interesting for domain types.
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
*
|
|
|
|
* NOTE: result tree is not guaranteed to show the correct exprType() for
|
|
|
|
* the domain; it may show the base type. Caller must relabel if needed.
|
2002-09-01 04:27:32 +02:00
|
|
|
*/
|
|
|
|
Node *
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
coerce_type_constraints(Node *arg, Oid typeId, CoercionForm cformat)
|
2002-09-01 04:27:32 +02:00
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
char *notNull = NULL;
|
|
|
|
int32 typmod = -1;
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
HeapTuple tup;
|
2002-11-15 03:50:21 +01:00
|
|
|
HeapTuple conTup;
|
2002-09-01 04:27:32 +02:00
|
|
|
Form_pg_type typTup;
|
|
|
|
|
2002-11-15 03:50:21 +01:00
|
|
|
ScanKeyData key[1];
|
|
|
|
int nkeys = 0;
|
|
|
|
SysScanDesc scan;
|
|
|
|
Relation conRel;
|
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
tup = SearchSysCache(TYPEOID,
|
|
|
|
ObjectIdGetDatum(typeId),
|
|
|
|
0, 0, 0);
|
|
|
|
if (!HeapTupleIsValid(tup))
|
|
|
|
elog(ERROR, "coerce_type_constraints: failed to lookup type %u",
|
|
|
|
typeId);
|
|
|
|
typTup = (Form_pg_type) GETSTRUCT(tup);
|
|
|
|
|
|
|
|
/* Test for NOT NULL Constraint */
|
|
|
|
if (typTup->typnotnull && notNull == NULL)
|
|
|
|
notNull = pstrdup(NameStr(typTup->typname));
|
|
|
|
|
2002-11-15 03:50:21 +01:00
|
|
|
/* Add CHECK Constraints to domains */
|
|
|
|
conRel = heap_openr(ConstraintRelationName, RowShareLock);
|
|
|
|
|
|
|
|
ScanKeyEntryInitialize(&key[nkeys++], 0x0,
|
|
|
|
Anum_pg_constraint_contypid, F_OIDEQ,
|
|
|
|
ObjectIdGetDatum(typeId));
|
|
|
|
|
|
|
|
scan = systable_beginscan(conRel, ConstraintTypidIndex, true,
|
|
|
|
SnapshotNow, nkeys, key);
|
|
|
|
|
|
|
|
while (HeapTupleIsValid(conTup = systable_getnext(scan)))
|
|
|
|
{
|
|
|
|
Datum val;
|
|
|
|
bool isNull;
|
|
|
|
ConstraintTest *r = makeNode(ConstraintTest);
|
|
|
|
Form_pg_constraint c = (Form_pg_constraint) GETSTRUCT(conTup);
|
|
|
|
|
|
|
|
/* Not expecting conbin to be NULL, but we'll test for it anyway */
|
|
|
|
val = fastgetattr(conTup,
|
|
|
|
Anum_pg_constraint_conbin,
|
|
|
|
conRel->rd_att, &isNull);
|
|
|
|
|
|
|
|
if (isNull)
|
|
|
|
elog(ERROR, "coerce_type_constraints: domain %s constraint %s has NULL conbin",
|
|
|
|
NameStr(typTup->typname), NameStr(c->conname));
|
|
|
|
|
|
|
|
r->arg = arg;
|
|
|
|
r->testtype = CONSTR_TEST_CHECK;
|
|
|
|
r->name = NameStr(c->conname);
|
|
|
|
r->domname = NameStr(typTup->typname);
|
|
|
|
r->check_expr = stringToNode(MemoryContextStrdup(CacheMemoryContext,
|
|
|
|
DatumGetCString(DirectFunctionCall1(textout,
|
|
|
|
val))));
|
|
|
|
|
|
|
|
arg = (Node *) r;
|
|
|
|
}
|
|
|
|
|
|
|
|
systable_endscan(scan);
|
|
|
|
heap_close(conRel, RowShareLock);
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
if (typTup->typtype != 'd')
|
|
|
|
{
|
|
|
|
/* Not a domain, so done */
|
|
|
|
ReleaseSysCache(tup);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Assert(typmod < 0);
|
|
|
|
|
|
|
|
typeId = typTup->typbasetype;
|
|
|
|
typmod = typTup->typtypmod;
|
|
|
|
ReleaseSysCache(tup);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If domain applies a typmod to its base type, do length coercion.
|
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (typmod >= 0)
|
|
|
|
arg = coerce_type_typmod(arg, typeId, typmod, cformat);
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
/*
|
2002-09-04 22:31:48 +02:00
|
|
|
* Only need to add one NOT NULL check regardless of how many domains
|
|
|
|
* in the stack request it. The topmost domain that requested it is
|
|
|
|
* used as the constraint name.
|
2002-09-01 04:27:32 +02:00
|
|
|
*/
|
|
|
|
if (notNull)
|
|
|
|
{
|
|
|
|
ConstraintTest *r = makeNode(ConstraintTest);
|
|
|
|
|
|
|
|
r->arg = arg;
|
|
|
|
r->testtype = CONSTR_TEST_NOTNULL;
|
2002-11-15 03:50:21 +01:00
|
|
|
r->name = "NOT NULL";
|
|
|
|
r->domname = notNull;
|
2002-09-01 04:27:32 +02:00
|
|
|
r->check_expr = NULL;
|
|
|
|
|
|
|
|
arg = (Node *) r;
|
2002-09-04 22:31:48 +02:00
|
|
|
}
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/*
|
|
|
|
* coerce_type_typmod()
|
|
|
|
* Force a value to a particular typmod, if meaningful and possible.
|
2000-01-17 01:14:49 +01:00
|
|
|
*
|
|
|
|
* This is applied to values that are going to be stored in a relation
|
|
|
|
* (where we have an atttypmod for the column) as well as values being
|
|
|
|
* explicitly CASTed (where the typmod comes from the target type spec).
|
|
|
|
*
|
|
|
|
* The caller must have already ensured that the value is of the correct
|
|
|
|
* type, typically by applying coerce_type.
|
|
|
|
*
|
2002-09-01 00:10:48 +02:00
|
|
|
* NOTE: this does not need to work on domain types, because any typmod
|
|
|
|
* coercion for a domain is considered to be part of the type coercion
|
2002-09-01 04:27:32 +02:00
|
|
|
* needed to produce the domain value in the first place. So, no getBaseType.
|
2000-01-17 01:14:49 +01:00
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
static Node *
|
|
|
|
coerce_type_typmod(Node *node, Oid targetTypeId, int32 targetTypMod,
|
|
|
|
CoercionForm cformat)
|
2000-01-17 01:14:49 +01:00
|
|
|
{
|
2002-03-20 20:45:13 +01:00
|
|
|
Oid funcId;
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
int nargs;
|
2000-01-17 01:14:49 +01:00
|
|
|
|
|
|
|
/*
|
2001-10-04 19:52:24 +02:00
|
|
|
* A negative typmod is assumed to mean that no coercion is wanted.
|
2000-01-17 01:14:49 +01:00
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (targetTypMod < 0 || targetTypMod == exprTypmod(node))
|
2000-01-17 01:14:49 +01:00
|
|
|
return node;
|
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
funcId = find_typmod_coercion_function(targetTypeId, &nargs);
|
2002-09-01 00:10:48 +02:00
|
|
|
|
2002-03-20 20:45:13 +01:00
|
|
|
if (OidIsValid(funcId))
|
2000-01-17 01:14:49 +01:00
|
|
|
{
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
List *args;
|
2002-03-20 20:45:13 +01:00
|
|
|
Const *cons;
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
Node *fcall;
|
2000-01-17 01:14:49 +01:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/* Pass given value, plus target typmod as an int4 constant */
|
2002-03-20 20:45:13 +01:00
|
|
|
cons = makeConst(INT4OID,
|
|
|
|
sizeof(int32),
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
Int32GetDatum(targetTypMod),
|
2002-03-20 20:45:13 +01:00
|
|
|
false,
|
2002-11-25 22:29:42 +01:00
|
|
|
true);
|
2000-01-17 01:14:49 +01:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
args = makeList2(node, cons);
|
|
|
|
|
|
|
|
if (nargs == 3)
|
|
|
|
{
|
|
|
|
/* Pass it a boolean isExplicit parameter, too */
|
|
|
|
cons = makeConst(BOOLOID,
|
|
|
|
sizeof(bool),
|
|
|
|
BoolGetDatum(cformat != COERCE_IMPLICIT_CAST),
|
|
|
|
false,
|
2002-11-25 22:29:42 +01:00
|
|
|
true);
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
|
|
|
|
args = lappend(args, cons);
|
|
|
|
}
|
|
|
|
|
|
|
|
fcall = build_func_call(funcId, targetTypeId, args, cformat);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the input is a constant, apply the length coercion
|
|
|
|
* function now instead of delaying to runtime.
|
|
|
|
*
|
|
|
|
* See the comments for the similar case in coerce_type.
|
|
|
|
*/
|
|
|
|
if (node && IsA(node, Const) &&
|
|
|
|
!((Const *) node)->constisnull)
|
|
|
|
node = eval_const_expressions(fcall);
|
|
|
|
else
|
|
|
|
node = fcall;
|
2000-01-17 01:14:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
1998-05-10 01:31:34 +02:00
|
|
|
|
2001-06-20 00:39:12 +02:00
|
|
|
/* coerce_to_boolean()
|
|
|
|
* Coerce an argument of a construct that requires boolean input
|
2002-05-13 01:43:04 +02:00
|
|
|
* (AND, OR, NOT, etc). Also check that input is not a set.
|
2001-06-20 00:39:12 +02:00
|
|
|
*
|
2002-05-13 01:43:04 +02:00
|
|
|
* Returns the possibly-transformed node tree.
|
2001-06-20 00:39:12 +02:00
|
|
|
*/
|
2002-05-13 01:43:04 +02:00
|
|
|
Node *
|
|
|
|
coerce_to_boolean(Node *node, const char *constructName)
|
2001-06-20 00:39:12 +02:00
|
|
|
{
|
2002-05-13 01:43:04 +02:00
|
|
|
Oid inputTypeId = exprType(node);
|
2001-06-20 00:39:12 +02:00
|
|
|
|
2002-05-13 01:43:04 +02:00
|
|
|
if (inputTypeId != BOOLOID)
|
|
|
|
{
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
node = coerce_to_target_type(node, inputTypeId,
|
|
|
|
BOOLOID, -1,
|
|
|
|
COERCION_ASSIGNMENT,
|
|
|
|
COERCE_IMPLICIT_CAST);
|
|
|
|
if (node == NULL)
|
2002-05-13 01:43:04 +02:00
|
|
|
{
|
|
|
|
/* translator: first %s is name of a SQL construct, eg WHERE */
|
|
|
|
elog(ERROR, "Argument of %s must be type boolean, not type %s",
|
|
|
|
constructName, format_type_be(inputTypeId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expression_returns_set(node))
|
|
|
|
{
|
|
|
|
/* translator: %s is name of a SQL construct, eg WHERE */
|
|
|
|
elog(ERROR, "Argument of %s must not be a set function",
|
|
|
|
constructName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
2001-06-20 00:39:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-05 21:11:39 +02:00
|
|
|
/* select_common_type()
|
|
|
|
* Determine the common supertype of a list of input expression types.
|
|
|
|
* This is used for determining the output type of CASE and UNION
|
|
|
|
* constructs.
|
|
|
|
*
|
|
|
|
* typeids is a nonempty integer list of type OIDs. Note that earlier items
|
|
|
|
* in the list will be preferred if there is doubt.
|
|
|
|
* 'context' is a phrase to use in the error message if we fail to select
|
|
|
|
* a usable type.
|
|
|
|
*/
|
|
|
|
Oid
|
|
|
|
select_common_type(List *typeids, const char *context)
|
|
|
|
{
|
|
|
|
Oid ptype;
|
|
|
|
CATEGORY pcategory;
|
|
|
|
List *l;
|
|
|
|
|
|
|
|
Assert(typeids != NIL);
|
|
|
|
ptype = (Oid) lfirsti(typeids);
|
|
|
|
pcategory = TypeCategory(ptype);
|
|
|
|
foreach(l, lnext(typeids))
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
Oid ntype = (Oid) lfirsti(l);
|
2000-10-05 21:11:39 +02:00
|
|
|
|
|
|
|
/* move on to next one if no new information... */
|
2001-10-03 07:29:27 +02:00
|
|
|
if ((ntype != InvalidOid) && (ntype != UNKNOWNOID) && (ntype != ptype))
|
2000-10-05 21:11:39 +02:00
|
|
|
{
|
2001-10-03 07:29:27 +02:00
|
|
|
if ((ptype == InvalidOid) || ptype == UNKNOWNOID)
|
2000-10-05 21:11:39 +02:00
|
|
|
{
|
|
|
|
/* so far, only nulls so take anything... */
|
|
|
|
ptype = ntype;
|
|
|
|
pcategory = TypeCategory(ptype);
|
|
|
|
}
|
|
|
|
else if (TypeCategory(ntype) != pcategory)
|
|
|
|
{
|
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* both types in different categories? then not much
|
|
|
|
* hope...
|
2000-10-05 21:11:39 +02:00
|
|
|
*/
|
2002-05-18 00:35:13 +02:00
|
|
|
elog(ERROR, "%s types '%s' and '%s' not matched",
|
|
|
|
context, format_type_be(ptype), format_type_be(ntype));
|
2000-10-05 21:11:39 +02:00
|
|
|
}
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
else if (!IsPreferredType(pcategory, ptype) &&
|
|
|
|
can_coerce_type(1, &ptype, &ntype, COERCION_IMPLICIT) &&
|
|
|
|
!can_coerce_type(1, &ntype, &ptype, COERCION_IMPLICIT))
|
2000-10-05 21:11:39 +02:00
|
|
|
{
|
|
|
|
/*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* take new type if can coerce to it implicitly but not the
|
|
|
|
* other way; but if we have a preferred type, stay on it.
|
2000-10-05 21:11:39 +02:00
|
|
|
*/
|
|
|
|
ptype = ntype;
|
|
|
|
pcategory = TypeCategory(ptype);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-11-09 05:14:32 +01:00
|
|
|
|
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* If all the inputs were UNKNOWN type --- ie, unknown-type literals
|
|
|
|
* --- then resolve as type TEXT. This situation comes up with
|
|
|
|
* constructs like SELECT (CASE WHEN foo THEN 'bar' ELSE 'baz' END);
|
|
|
|
* SELECT 'foo' UNION SELECT 'bar'; It might seem desirable to leave
|
|
|
|
* the construct's output type as UNKNOWN, but that really doesn't
|
|
|
|
* work, because we'd probably end up needing a runtime coercion from
|
|
|
|
* UNKNOWN to something else, and we usually won't have it. We need
|
|
|
|
* to coerce the unknown literals while they are still literals, so a
|
|
|
|
* decision has to be made now.
|
2000-11-09 05:14:32 +01:00
|
|
|
*/
|
|
|
|
if (ptype == UNKNOWNOID)
|
|
|
|
ptype = TEXTOID;
|
|
|
|
|
2000-10-05 21:11:39 +02:00
|
|
|
return ptype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* coerce_to_common_type()
|
|
|
|
* Coerce an expression to the given type.
|
|
|
|
*
|
|
|
|
* This is used following select_common_type() to coerce the individual
|
|
|
|
* expressions to the desired type. 'context' is a phrase to use in the
|
|
|
|
* error message if we fail to coerce.
|
|
|
|
*/
|
|
|
|
Node *
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
coerce_to_common_type(Node *node, Oid targetTypeId, const char *context)
|
2000-10-05 21:11:39 +02:00
|
|
|
{
|
|
|
|
Oid inputTypeId = exprType(node);
|
|
|
|
|
|
|
|
if (inputTypeId == targetTypeId)
|
|
|
|
return node; /* no work */
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (can_coerce_type(1, &inputTypeId, &targetTypeId, COERCION_IMPLICIT))
|
|
|
|
node = coerce_type(node, inputTypeId, targetTypeId,
|
|
|
|
COERCION_IMPLICIT, COERCE_IMPLICIT_CAST);
|
2000-10-05 21:11:39 +02:00
|
|
|
else
|
2002-05-18 00:35:13 +02:00
|
|
|
elog(ERROR, "%s unable to convert to type %s",
|
|
|
|
context, format_type_be(targetTypeId));
|
2000-10-05 21:11:39 +02:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-10 01:31:34 +02:00
|
|
|
/* TypeCategory()
|
|
|
|
* Assign a category to the specified OID.
|
2001-10-03 07:29:27 +02:00
|
|
|
* XXX This should be moved to system catalog lookups
|
|
|
|
* to allow for better type extensibility.
|
|
|
|
* - thomas 2001-09-30
|
1998-05-10 01:31:34 +02:00
|
|
|
*/
|
|
|
|
CATEGORY
|
|
|
|
TypeCategory(Oid inType)
|
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
CATEGORY result;
|
1998-05-10 01:31:34 +02:00
|
|
|
|
|
|
|
switch (inType)
|
|
|
|
{
|
|
|
|
case (BOOLOID):
|
|
|
|
result = BOOLEAN_TYPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (CHAROID):
|
2000-03-12 00:19:50 +01:00
|
|
|
case (NAMEOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
case (BPCHAROID):
|
|
|
|
case (VARCHAROID):
|
|
|
|
case (TEXTOID):
|
|
|
|
result = STRING_TYPE;
|
|
|
|
break;
|
|
|
|
|
2001-05-22 18:37:17 +02:00
|
|
|
case (BITOID):
|
2000-04-08 21:29:40 +02:00
|
|
|
case (VARBITOID):
|
2000-11-17 20:57:48 +01:00
|
|
|
result = BITSTRING_TYPE;
|
2000-04-08 21:29:40 +02:00
|
|
|
break;
|
|
|
|
|
1998-08-14 18:07:00 +02:00
|
|
|
case (OIDOID):
|
2000-02-27 19:54:43 +01:00
|
|
|
case (REGPROCOID):
|
2002-04-25 04:56:56 +02:00
|
|
|
case (REGPROCEDUREOID):
|
|
|
|
case (REGOPEROID):
|
|
|
|
case (REGOPERATOROID):
|
|
|
|
case (REGCLASSOID):
|
|
|
|
case (REGTYPEOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
case (INT2OID):
|
|
|
|
case (INT4OID):
|
1998-07-08 16:04:11 +02:00
|
|
|
case (INT8OID):
|
1998-05-10 01:31:34 +02:00
|
|
|
case (FLOAT4OID):
|
|
|
|
case (FLOAT8OID):
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
case (NUMERICOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
case (CASHOID):
|
|
|
|
result = NUMERIC_TYPE;
|
|
|
|
break;
|
|
|
|
|
2000-02-20 07:28:42 +01:00
|
|
|
case (DATEOID):
|
|
|
|
case (TIMEOID):
|
2000-03-15 00:06:59 +01:00
|
|
|
case (TIMETZOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
case (ABSTIMEOID):
|
|
|
|
case (TIMESTAMPOID):
|
2001-09-28 10:09:14 +02:00
|
|
|
case (TIMESTAMPTZOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
result = DATETIME_TYPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (RELTIMEOID):
|
2000-02-20 07:28:42 +01:00
|
|
|
case (TINTERVALOID):
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
case (INTERVALOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
result = TIMESPAN_TYPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (POINTOID):
|
|
|
|
case (LSEGOID):
|
|
|
|
case (PATHOID):
|
2000-03-12 00:19:50 +01:00
|
|
|
case (BOXOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
case (POLYGONOID):
|
2000-03-12 00:19:50 +01:00
|
|
|
case (LINEOID):
|
|
|
|
case (CIRCLEOID):
|
1998-05-10 01:31:34 +02:00
|
|
|
result = GEOMETRIC_TYPE;
|
|
|
|
break;
|
|
|
|
|
1998-10-22 15:51:07 +02:00
|
|
|
case (INETOID):
|
|
|
|
case (CIDROID):
|
|
|
|
result = NETWORK_TYPE;
|
|
|
|
break;
|
|
|
|
|
2000-03-12 00:19:50 +01:00
|
|
|
case (UNKNOWNOID):
|
|
|
|
case (InvalidOid):
|
|
|
|
result = UNKNOWN_TYPE;
|
|
|
|
break;
|
|
|
|
|
1998-05-10 01:31:34 +02:00
|
|
|
default:
|
|
|
|
result = USER_TYPE;
|
|
|
|
break;
|
|
|
|
}
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1998-09-01 06:40:42 +02:00
|
|
|
} /* TypeCategory() */
|
1998-05-10 01:31:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* IsPreferredType()
|
1998-12-04 16:34:49 +01:00
|
|
|
* Check if this type is a preferred type.
|
2001-10-03 07:29:27 +02:00
|
|
|
* XXX This should be moved to system catalog lookups
|
|
|
|
* to allow for better type extensibility.
|
|
|
|
* - thomas 2001-09-30
|
1998-05-10 01:31:34 +02:00
|
|
|
*/
|
|
|
|
bool
|
|
|
|
IsPreferredType(CATEGORY category, Oid type)
|
|
|
|
{
|
2001-10-03 07:29:27 +02:00
|
|
|
return (type == PreferredType(category, type));
|
1998-09-01 06:40:42 +02:00
|
|
|
} /* IsPreferredType() */
|
1998-05-10 01:31:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* PreferredType()
|
1998-05-29 16:00:24 +02:00
|
|
|
* Return the preferred type OID for the specified category.
|
2001-10-03 07:29:27 +02:00
|
|
|
* XXX This should be moved to system catalog lookups
|
|
|
|
* to allow for better type extensibility.
|
|
|
|
* - thomas 2001-09-30
|
1998-05-10 01:31:34 +02:00
|
|
|
*/
|
1998-10-08 20:30:52 +02:00
|
|
|
static Oid
|
1998-05-10 01:31:34 +02:00
|
|
|
PreferredType(CATEGORY category, Oid type)
|
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
Oid result;
|
1998-05-10 01:31:34 +02:00
|
|
|
|
|
|
|
switch (category)
|
|
|
|
{
|
|
|
|
case (BOOLEAN_TYPE):
|
|
|
|
result = BOOLOID;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (STRING_TYPE):
|
|
|
|
result = TEXTOID;
|
|
|
|
break;
|
|
|
|
|
2000-11-17 20:57:48 +01:00
|
|
|
case (BITSTRING_TYPE):
|
|
|
|
result = VARBITOID;
|
|
|
|
break;
|
|
|
|
|
1998-05-10 01:31:34 +02:00
|
|
|
case (NUMERIC_TYPE):
|
2002-09-01 04:27:32 +02:00
|
|
|
if (type == OIDOID ||
|
|
|
|
type == REGPROCOID ||
|
|
|
|
type == REGPROCEDUREOID ||
|
|
|
|
type == REGOPEROID ||
|
|
|
|
type == REGOPERATOROID ||
|
|
|
|
type == REGCLASSOID ||
|
|
|
|
type == REGTYPEOID)
|
1998-08-14 18:07:00 +02:00
|
|
|
result = OIDOID;
|
|
|
|
else
|
|
|
|
result = FLOAT8OID;
|
1998-05-10 01:31:34 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case (DATETIME_TYPE):
|
2001-09-28 10:09:14 +02:00
|
|
|
if (type == DATEOID)
|
|
|
|
result = TIMESTAMPOID;
|
|
|
|
else
|
|
|
|
result = TIMESTAMPTZOID;
|
1998-05-10 01:31:34 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case (TIMESPAN_TYPE):
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
result = INTERVALOID;
|
1998-05-10 01:31:34 +02:00
|
|
|
break;
|
|
|
|
|
1998-10-22 15:51:07 +02:00
|
|
|
case (NETWORK_TYPE):
|
|
|
|
result = INETOID;
|
|
|
|
break;
|
1999-05-25 18:15:34 +02:00
|
|
|
|
1998-05-10 01:31:34 +02:00
|
|
|
case (GEOMETRIC_TYPE):
|
|
|
|
case (USER_TYPE):
|
|
|
|
result = type;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = UNKNOWNOID;
|
|
|
|
break;
|
|
|
|
}
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1998-09-01 06:40:42 +02:00
|
|
|
} /* PreferredType() */
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/* IsBinaryCoercible()
|
|
|
|
* Check if srctype is binary-coercible to targettype.
|
2002-03-20 20:45:13 +01:00
|
|
|
*
|
2002-09-01 04:27:32 +02:00
|
|
|
* This notion allows us to cheat and directly exchange values without
|
|
|
|
* going through the trouble of calling a conversion function.
|
2002-03-20 20:45:13 +01:00
|
|
|
*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* As of 7.3, binary coercibility isn't hardwired into the code anymore.
|
|
|
|
* We consider two types binary-coercible if there is an implicitly
|
|
|
|
* invokable, no-function-needed pg_cast entry.
|
|
|
|
*
|
|
|
|
* This function replaces IsBinaryCompatible(), which was an inherently
|
|
|
|
* symmetric test. Since the pg_cast entries aren't necessarily symmetric,
|
|
|
|
* the order of the operands is now significant.
|
2002-09-01 04:27:32 +02:00
|
|
|
*/
|
|
|
|
bool
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
IsBinaryCoercible(Oid srctype, Oid targettype)
|
2002-09-01 04:27:32 +02:00
|
|
|
{
|
|
|
|
HeapTuple tuple;
|
|
|
|
Form_pg_cast castForm;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
/* Fast path if same type */
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (srctype == targettype)
|
2002-09-01 04:27:32 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Perhaps the types are domains; if so, look at their base types */
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (OidIsValid(srctype))
|
|
|
|
srctype = getBaseType(srctype);
|
|
|
|
if (OidIsValid(targettype))
|
|
|
|
targettype = getBaseType(targettype);
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
/* Somewhat-fast path if same base type */
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (srctype == targettype)
|
2002-09-01 04:27:32 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Else look in pg_cast */
|
|
|
|
tuple = SearchSysCache(CASTSOURCETARGET,
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
ObjectIdGetDatum(srctype),
|
|
|
|
ObjectIdGetDatum(targettype),
|
2002-09-01 04:27:32 +02:00
|
|
|
0, 0);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
return false; /* no cast */
|
|
|
|
castForm = (Form_pg_cast) GETSTRUCT(tuple);
|
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
result = (castForm->castfunc == InvalidOid &&
|
|
|
|
castForm->castcontext == COERCION_CODE_IMPLICIT);
|
2002-09-01 04:27:32 +02:00
|
|
|
|
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find_coercion_pathway
|
|
|
|
* Look for a coercion pathway between two types.
|
2002-03-20 20:45:13 +01:00
|
|
|
*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* ccontext determines the set of available casts.
|
|
|
|
*
|
|
|
|
* If we find a suitable entry in pg_cast, return TRUE, and set *funcid
|
2002-09-01 04:27:32 +02:00
|
|
|
* to the castfunc value (which may be InvalidOid for a binary-compatible
|
|
|
|
* coercion).
|
2002-03-19 03:18:25 +01:00
|
|
|
*/
|
2002-10-25 00:09:00 +02:00
|
|
|
bool
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
|
|
|
|
CoercionContext ccontext,
|
2002-09-01 04:27:32 +02:00
|
|
|
Oid *funcid)
|
2002-07-19 01:11:32 +02:00
|
|
|
{
|
2002-09-01 04:27:32 +02:00
|
|
|
bool result = false;
|
2002-07-19 01:11:32 +02:00
|
|
|
HeapTuple tuple;
|
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
*funcid = InvalidOid;
|
|
|
|
|
|
|
|
/* Perhaps the types are domains; if so, look at their base types */
|
|
|
|
if (OidIsValid(sourceTypeId))
|
|
|
|
sourceTypeId = getBaseType(sourceTypeId);
|
|
|
|
if (OidIsValid(targetTypeId))
|
|
|
|
targetTypeId = getBaseType(targetTypeId);
|
|
|
|
|
|
|
|
/* Domains are automatically binary-compatible with their base type */
|
|
|
|
if (sourceTypeId == targetTypeId)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Else look in pg_cast */
|
2002-07-19 01:11:32 +02:00
|
|
|
tuple = SearchSysCache(CASTSOURCETARGET,
|
|
|
|
ObjectIdGetDatum(sourceTypeId),
|
|
|
|
ObjectIdGetDatum(targetTypeId),
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
if (HeapTupleIsValid(tuple))
|
|
|
|
{
|
2002-09-01 04:27:32 +02:00
|
|
|
Form_pg_cast castForm = (Form_pg_cast) GETSTRUCT(tuple);
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
CoercionContext castcontext;
|
|
|
|
|
|
|
|
/* convert char value for castcontext to CoercionContext enum */
|
|
|
|
switch (castForm->castcontext)
|
|
|
|
{
|
|
|
|
case COERCION_CODE_IMPLICIT:
|
|
|
|
castcontext = COERCION_IMPLICIT;
|
|
|
|
break;
|
|
|
|
case COERCION_CODE_ASSIGNMENT:
|
|
|
|
castcontext = COERCION_ASSIGNMENT;
|
|
|
|
break;
|
|
|
|
case COERCION_CODE_EXPLICIT:
|
|
|
|
castcontext = COERCION_EXPLICIT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
elog(ERROR, "find_coercion_pathway: bogus castcontext %c",
|
|
|
|
castForm->castcontext);
|
|
|
|
castcontext = 0; /* keep compiler quiet */
|
|
|
|
break;
|
|
|
|
}
|
2002-07-19 01:11:32 +02:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/* Rely on ordering of enum for correct behavior here */
|
|
|
|
if (ccontext >= castcontext)
|
2002-09-01 04:27:32 +02:00
|
|
|
{
|
|
|
|
*funcid = castForm->castfunc;
|
|
|
|
result = true;
|
|
|
|
}
|
2002-07-19 01:11:32 +02:00
|
|
|
|
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
}
|
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
return result;
|
2002-07-19 01:11:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-01 04:27:32 +02:00
|
|
|
/*
|
|
|
|
* find_typmod_coercion_function -- does the given type need length coercion?
|
|
|
|
*
|
|
|
|
* If the target type possesses a function named for the type
|
|
|
|
* and having parameter signature (targettype, int4), we assume that
|
|
|
|
* the type requires coercion to its own length and that the said
|
|
|
|
* function should be invoked to do that.
|
|
|
|
*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* Alternatively, the length-coercing function may have the signature
|
|
|
|
* (targettype, int4, bool). On success, *nargs is set to report which
|
|
|
|
* signature we found.
|
|
|
|
*
|
2002-09-01 04:27:32 +02:00
|
|
|
* "bpchar" (ie, char(N)) and "numeric" are examples of such types.
|
|
|
|
*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* If the given type is a varlena array type, we do not look for a coercion
|
|
|
|
* function associated directly with the array type, but instead look for
|
|
|
|
* one associated with the element type. If one exists, we report
|
|
|
|
* array_length_coerce() as the coercion function to use.
|
|
|
|
*
|
2002-09-01 04:27:32 +02:00
|
|
|
* This mechanism may seem pretty grotty and in need of replacement by
|
|
|
|
* something in pg_cast, but since typmod is only interesting for datatypes
|
|
|
|
* that have special handling in the grammar, there's not really much
|
|
|
|
* percentage in making it any easier to apply such coercions ...
|
|
|
|
*/
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
Oid
|
|
|
|
find_typmod_coercion_function(Oid typeId, int *nargs)
|
2002-03-19 03:18:25 +01:00
|
|
|
{
|
2002-04-11 22:00:18 +02:00
|
|
|
Oid funcid = InvalidOid;
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
bool isArray = false;
|
2002-04-09 22:35:55 +02:00
|
|
|
Type targetType;
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
Form_pg_type typeForm;
|
2002-04-09 22:35:55 +02:00
|
|
|
char *typname;
|
|
|
|
Oid typnamespace;
|
2002-03-20 20:45:13 +01:00
|
|
|
Oid oid_array[FUNC_MAX_ARGS];
|
|
|
|
HeapTuple ftup;
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2002-07-19 01:11:32 +02:00
|
|
|
targetType = typeidType(typeId);
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
typeForm = (Form_pg_type) GETSTRUCT(targetType);
|
2002-04-09 22:35:55 +02:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/* Check for a varlena array type (and not a domain) */
|
|
|
|
if (typeForm->typelem != InvalidOid &&
|
|
|
|
typeForm->typlen == -1 &&
|
|
|
|
typeForm->typtype != 'd')
|
|
|
|
{
|
|
|
|
/* Yes, switch our attention to the element type */
|
|
|
|
typeId = typeForm->typelem;
|
|
|
|
ReleaseSysCache(targetType);
|
|
|
|
targetType = typeidType(typeId);
|
|
|
|
typeForm = (Form_pg_type) GETSTRUCT(targetType);
|
|
|
|
isArray = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function name is same as type internal name, and in same namespace */
|
|
|
|
typname = NameStr(typeForm->typname);
|
|
|
|
typnamespace = typeForm->typnamespace;
|
|
|
|
|
|
|
|
/* First look for parameters (type, int4) */
|
2002-03-20 20:45:13 +01:00
|
|
|
MemSet(oid_array, 0, FUNC_MAX_ARGS * sizeof(Oid));
|
2002-07-19 01:11:32 +02:00
|
|
|
oid_array[0] = typeId;
|
|
|
|
oid_array[1] = INT4OID;
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
*nargs = 2;
|
2002-03-20 20:45:13 +01:00
|
|
|
|
2002-04-09 22:35:55 +02:00
|
|
|
ftup = SearchSysCache(PROCNAMENSP,
|
|
|
|
CStringGetDatum(typname),
|
2002-07-19 01:11:32 +02:00
|
|
|
Int16GetDatum(2),
|
2002-03-20 20:45:13 +01:00
|
|
|
PointerGetDatum(oid_array),
|
2002-04-09 22:35:55 +02:00
|
|
|
ObjectIdGetDatum(typnamespace));
|
2002-04-11 22:00:18 +02:00
|
|
|
if (HeapTupleIsValid(ftup))
|
2002-03-20 20:45:13 +01:00
|
|
|
{
|
2002-04-11 22:00:18 +02:00
|
|
|
Form_pg_proc pform = (Form_pg_proc) GETSTRUCT(ftup);
|
|
|
|
|
|
|
|
/* Make sure the function's result type is as expected */
|
2002-07-19 01:11:32 +02:00
|
|
|
if (pform->prorettype == typeId && !pform->proretset &&
|
2002-04-11 22:00:18 +02:00
|
|
|
!pform->proisagg)
|
|
|
|
{
|
2002-07-19 01:11:32 +02:00
|
|
|
/* Okay to use it */
|
2002-07-20 07:29:01 +02:00
|
|
|
funcid = HeapTupleGetOid(ftup);
|
2002-04-11 22:00:18 +02:00
|
|
|
}
|
2002-03-20 20:45:13 +01:00
|
|
|
ReleaseSysCache(ftup);
|
|
|
|
}
|
2002-04-11 22:00:18 +02:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
if (!OidIsValid(funcid))
|
|
|
|
{
|
|
|
|
/* Didn't find a function, so now try (type, int4, bool) */
|
|
|
|
oid_array[2] = BOOLOID;
|
|
|
|
*nargs = 3;
|
|
|
|
|
|
|
|
ftup = SearchSysCache(PROCNAMENSP,
|
|
|
|
CStringGetDatum(typname),
|
|
|
|
Int16GetDatum(3),
|
|
|
|
PointerGetDatum(oid_array),
|
|
|
|
ObjectIdGetDatum(typnamespace));
|
|
|
|
if (HeapTupleIsValid(ftup))
|
|
|
|
{
|
|
|
|
Form_pg_proc pform = (Form_pg_proc) GETSTRUCT(ftup);
|
|
|
|
|
|
|
|
/* Make sure the function's result type is as expected */
|
|
|
|
if (pform->prorettype == typeId && !pform->proretset &&
|
|
|
|
!pform->proisagg)
|
|
|
|
{
|
|
|
|
/* Okay to use it */
|
|
|
|
funcid = HeapTupleGetOid(ftup);
|
|
|
|
}
|
|
|
|
ReleaseSysCache(ftup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-09 22:35:55 +02:00
|
|
|
ReleaseSysCache(targetType);
|
2002-09-01 04:27:32 +02:00
|
|
|
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
/*
|
|
|
|
* Now, if we did find a coercion function for an array element type,
|
|
|
|
* report array_length_coerce() as the function to use. We know it
|
|
|
|
* takes three arguments always.
|
|
|
|
*/
|
|
|
|
if (isArray && OidIsValid(funcid))
|
|
|
|
{
|
|
|
|
funcid = F_ARRAY_LENGTH_COERCE;
|
|
|
|
*nargs = 3;
|
|
|
|
}
|
|
|
|
|
2002-03-20 20:45:13 +01:00
|
|
|
return funcid;
|
|
|
|
}
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2002-03-20 20:45:13 +01:00
|
|
|
/*
|
|
|
|
* Build an expression tree representing a function call.
|
|
|
|
*
|
|
|
|
* The argument expressions must have been transformed already.
|
|
|
|
*/
|
|
|
|
static Node *
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
build_func_call(Oid funcid, Oid rettype, List *args, CoercionForm fformat)
|
2002-03-20 20:45:13 +01:00
|
|
|
{
|
|
|
|
Func *funcnode;
|
|
|
|
Expr *expr;
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2002-03-20 20:45:13 +01:00
|
|
|
funcnode = makeNode(Func);
|
|
|
|
funcnode->funcid = funcid;
|
2002-05-13 01:43:04 +02:00
|
|
|
funcnode->funcresulttype = rettype;
|
2002-09-04 22:31:48 +02:00
|
|
|
funcnode->funcretset = false; /* only possible case here */
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
funcnode->funcformat = fformat;
|
2002-03-20 20:45:13 +01:00
|
|
|
funcnode->func_fcache = NULL;
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2002-03-20 20:45:13 +01:00
|
|
|
expr = makeNode(Expr);
|
|
|
|
expr->typeOid = rettype;
|
|
|
|
expr->opType = FUNC_EXPR;
|
|
|
|
expr->oper = (Node *) funcnode;
|
|
|
|
expr->args = args;
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2002-03-20 20:45:13 +01:00
|
|
|
return (Node *) expr;
|
2002-03-19 03:18:25 +01:00
|
|
|
}
|