1998-05-09 19:31:34 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* parse_coerce.h
|
2000-01-16 19:14:49 -05:00
|
|
|
* Routines for type coercion.
|
1998-05-09 19:31:34 -04: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 17:35:25 -04:00
|
|
|
*
|
2007-01-05 17:20:05 -05:00
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1998-05-09 19:31:34 -04:00
|
|
|
*
|
2007-11-15 16:14:46 -05:00
|
|
|
* $PostgreSQL: pgsql/src/include/parser/parse_coerce.h,v 1.72 2007/11/15 21:14:44 momjian Exp $
|
1998-05-09 19:31:34 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef PARSE_COERCE_H
|
|
|
|
|
#define PARSE_COERCE_H
|
|
|
|
|
|
1999-07-16 13:07:40 -04:00
|
|
|
#include "parser/parse_node.h"
|
1999-07-13 21:20:30 -04:00
|
|
|
|
2003-04-29 18:13:11 -04:00
|
|
|
|
2007-06-05 17:31:09 -04:00
|
|
|
/* Type categories (kluge ... ought to be extensible) */
|
1998-09-01 00:40:42 -04:00
|
|
|
typedef enum CATEGORY
|
|
|
|
|
{
|
2001-10-28 01:26:15 -05:00
|
|
|
INVALID_TYPE,
|
|
|
|
|
UNKNOWN_TYPE,
|
2003-04-08 19:20:04 -04:00
|
|
|
GENERIC_TYPE,
|
2001-10-28 01:26:15 -05:00
|
|
|
BOOLEAN_TYPE,
|
|
|
|
|
STRING_TYPE,
|
|
|
|
|
BITSTRING_TYPE,
|
|
|
|
|
NUMERIC_TYPE,
|
|
|
|
|
DATETIME_TYPE,
|
|
|
|
|
TIMESPAN_TYPE,
|
|
|
|
|
GEOMETRIC_TYPE,
|
|
|
|
|
NETWORK_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 17:35:25 -04:00
|
|
|
USER_TYPE
|
1999-05-25 18:43:53 -04:00
|
|
|
} CATEGORY;
|
1998-05-09 19:31:34 -04:00
|
|
|
|
2007-06-05 17:31:09 -04:00
|
|
|
/* Result codes for find_coercion_pathway */
|
|
|
|
|
typedef enum CoercionPathType
|
|
|
|
|
{
|
|
|
|
|
COERCION_PATH_NONE, /* failed to find any coercion pathway */
|
|
|
|
|
COERCION_PATH_FUNC, /* apply the specified coercion function */
|
|
|
|
|
COERCION_PATH_RELABELTYPE, /* binary-compatible cast, no function */
|
|
|
|
|
COERCION_PATH_ARRAYCOERCE, /* need an ArrayCoerceExpr node */
|
|
|
|
|
COERCION_PATH_COERCEVIAIO /* need a CoerceViaIO node */
|
2007-11-15 16:14:46 -05:00
|
|
|
} CoercionPathType;
|
2007-06-05 17:31:09 -04:00
|
|
|
|
1998-05-09 19:31:34 -04: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 17:35:25 -04:00
|
|
|
extern bool IsBinaryCoercible(Oid srctype, Oid targettype);
|
1998-05-09 19:31:34 -04:00
|
|
|
extern bool IsPreferredType(CATEGORY category, Oid type);
|
|
|
|
|
extern CATEGORY TypeCategory(Oid type);
|
|
|
|
|
|
2003-04-29 18:13:11 -04:00
|
|
|
extern Node *coerce_to_target_type(ParseState *pstate,
|
2003-08-03 20:43:34 -04:00
|
|
|
Node *expr, Oid exprtype,
|
|
|
|
|
Oid targettype, int32 targettypmod,
|
|
|
|
|
CoercionContext ccontext,
|
|
|
|
|
CoercionForm cformat);
|
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 17:35:25 -04:00
|
|
|
extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *target_typeids,
|
2003-08-03 20:43:34 -04:00
|
|
|
CoercionContext ccontext);
|
2003-04-29 18:13:11 -04:00
|
|
|
extern Node *coerce_type(ParseState *pstate, Node *node,
|
2004-06-15 21:27:00 -04:00
|
|
|
Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod,
|
2003-08-03 20:43:34 -04:00
|
|
|
CoercionContext ccontext, CoercionForm cformat);
|
2006-04-05 18:11:58 -04:00
|
|
|
extern Node *coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod,
|
|
|
|
|
Oid typeId,
|
2004-11-06 12:46:38 -05:00
|
|
|
CoercionForm cformat, bool hideInputCoercion,
|
|
|
|
|
bool lengthCoercionDone);
|
1998-05-09 19:31:34 -04:00
|
|
|
|
2003-04-29 18:13:11 -04:00
|
|
|
extern Node *coerce_to_boolean(ParseState *pstate, Node *node,
|
2003-08-03 20:43:34 -04:00
|
|
|
const char *constructName);
|
2006-12-23 19:29:20 -05:00
|
|
|
extern Node *coerce_to_specific_type(ParseState *pstate, Node *node,
|
2007-11-15 16:14:46 -05:00
|
|
|
Oid targetTypeId,
|
|
|
|
|
const char *constructName);
|
2006-07-26 15:31:51 -04:00
|
|
|
|
2001-03-21 23:01:46 -05:00
|
|
|
extern Oid select_common_type(List *typeids, const char *context);
|
2003-04-29 18:13:11 -04:00
|
|
|
extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
|
2003-08-03 20:43:34 -04:00
|
|
|
Oid targetTypeId,
|
|
|
|
|
const char *context);
|
2001-10-28 01:26:15 -05:00
|
|
|
|
2003-04-08 19:20:04 -04:00
|
|
|
extern bool check_generic_type_consistency(Oid *actual_arg_types,
|
2003-08-03 20:43:34 -04:00
|
|
|
Oid *declared_arg_types,
|
|
|
|
|
int nargs);
|
2003-04-08 19:20:04 -04:00
|
|
|
extern Oid enforce_generic_type_consistency(Oid *actual_arg_types,
|
2003-08-03 20:43:34 -04:00
|
|
|
Oid *declared_arg_types,
|
|
|
|
|
int nargs,
|
|
|
|
|
Oid rettype);
|
2003-07-01 15:10:53 -04:00
|
|
|
extern Oid resolve_generic_type(Oid declared_type,
|
2003-08-03 20:43:34 -04:00
|
|
|
Oid context_actual_type,
|
|
|
|
|
Oid context_declared_type);
|
2003-04-08 19:20:04 -04:00
|
|
|
|
2007-06-05 17:31:09 -04:00
|
|
|
extern CoercionPathType find_coercion_pathway(Oid targetTypeId,
|
2007-11-15 16:14:46 -05:00
|
|
|
Oid sourceTypeId,
|
|
|
|
|
CoercionContext ccontext,
|
|
|
|
|
Oid *funcid);
|
2007-06-05 17:31:09 -04:00
|
|
|
extern CoercionPathType find_typmod_coercion_function(Oid typeId,
|
2007-11-15 16:14:46 -05: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 17:35:25 -04:00
|
|
|
|
2001-11-05 12:46:40 -05:00
|
|
|
#endif /* PARSE_COERCE_H */
|