Header And Logo

PostgreSQL
| The world's most advanced open source database.

pg_cast.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pg_cast.h
00004  *    definition of the system "type casts" relation (pg_cast)
00005  *    along with the relation's initial contents.
00006  *
00007  * As of Postgres 8.0, pg_cast describes not only type coercion functions
00008  * but also length coercion functions.
00009  *
00010  *
00011  * Copyright (c) 2002-2013, PostgreSQL Global Development Group
00012  *
00013  * src/include/catalog/pg_cast.h
00014  *
00015  * NOTES
00016  *    the genbki.pl script reads this file and generates .bki
00017  *    information from the DATA() statements.
00018  *
00019  *-------------------------------------------------------------------------
00020  */
00021 #ifndef PG_CAST_H
00022 #define PG_CAST_H
00023 
00024 #include "catalog/genbki.h"
00025 
00026 /* ----------------
00027  *      pg_cast definition.  cpp turns this into
00028  *      typedef struct FormData_pg_cast
00029  * ----------------
00030  */
00031 #define CastRelationId  2605
00032 
00033 CATALOG(pg_cast,2605)
00034 {
00035     Oid         castsource;     /* source datatype for cast */
00036     Oid         casttarget;     /* destination datatype for cast */
00037     Oid         castfunc;       /* cast function; 0 = binary coercible */
00038     char        castcontext;    /* contexts in which cast can be used */
00039     char        castmethod;     /* cast method */
00040 } FormData_pg_cast;
00041 
00042 typedef FormData_pg_cast *Form_pg_cast;
00043 
00044 /*
00045  * The allowable values for pg_cast.castcontext are specified by this enum.
00046  * Since castcontext is stored as a "char", we use ASCII codes for human
00047  * convenience in reading the table.  Note that internally to the backend,
00048  * these values are converted to the CoercionContext enum (see primnodes.h),
00049  * which is defined to sort in a convenient order; the ASCII codes don't
00050  * have to sort in any special order.
00051  */
00052 
00053 typedef enum CoercionCodes
00054 {
00055     COERCION_CODE_IMPLICIT = 'i',       /* coercion in context of expression */
00056     COERCION_CODE_ASSIGNMENT = 'a',     /* coercion in context of assignment */
00057     COERCION_CODE_EXPLICIT = 'e'    /* explicit cast operation */
00058 } CoercionCodes;
00059 
00060 /*
00061  * The allowable values for pg_cast.castmethod are specified by this enum.
00062  * Since castcontext is stored as a "char", we use ASCII codes for human
00063  * convenience in reading the table.
00064  */
00065 typedef enum CoercionMethod
00066 {
00067     COERCION_METHOD_FUNCTION = 'f',     /* use a function */
00068     COERCION_METHOD_BINARY = 'b',       /* types are binary-compatible */
00069     COERCION_METHOD_INOUT = 'i' /* use input/output functions */
00070 } CoercionMethod;
00071 
00072 
00073 /* ----------------
00074  *      compiler constants for pg_cast
00075  * ----------------
00076  */
00077 #define Natts_pg_cast               5
00078 #define Anum_pg_cast_castsource     1
00079 #define Anum_pg_cast_casttarget     2
00080 #define Anum_pg_cast_castfunc       3
00081 #define Anum_pg_cast_castcontext    4
00082 #define Anum_pg_cast_castmethod     5
00083 
00084 /* ----------------
00085  *      initial contents of pg_cast
00086  *
00087  * Note: this table has OIDs, but we don't bother to assign them manually,
00088  * since nothing needs to know the specific OID of any built-in cast.
00089  * ----------------
00090  */
00091 
00092 /*
00093  * Numeric category: implicit casts are allowed in the direction
00094  * int2->int4->int8->numeric->float4->float8, while casts in the
00095  * reverse direction are assignment-only.
00096  */
00097 DATA(insert (   20   21  714 a f ));
00098 DATA(insert (   20   23  480 a f ));
00099 DATA(insert (   20  700  652 i f ));
00100 DATA(insert (   20  701  482 i f ));
00101 DATA(insert (   20 1700 1781 i f ));
00102 DATA(insert (   21   20  754 i f ));
00103 DATA(insert (   21   23  313 i f ));
00104 DATA(insert (   21  700  236 i f ));
00105 DATA(insert (   21  701  235 i f ));
00106 DATA(insert (   21 1700 1782 i f ));
00107 DATA(insert (   23   20  481 i f ));
00108 DATA(insert (   23   21  314 a f ));
00109 DATA(insert (   23  700  318 i f ));
00110 DATA(insert (   23  701  316 i f ));
00111 DATA(insert (   23 1700 1740 i f ));
00112 DATA(insert (  700   20  653 a f ));
00113 DATA(insert (  700   21  238 a f ));
00114 DATA(insert (  700   23  319 a f ));
00115 DATA(insert (  700  701  311 i f ));
00116 DATA(insert (  700 1700 1742 a f ));
00117 DATA(insert (  701   20  483 a f ));
00118 DATA(insert (  701   21  237 a f ));
00119 DATA(insert (  701   23  317 a f ));
00120 DATA(insert (  701  700  312 a f ));
00121 DATA(insert (  701 1700 1743 a f ));
00122 DATA(insert ( 1700   20 1779 a f ));
00123 DATA(insert ( 1700   21 1783 a f ));
00124 DATA(insert ( 1700   23 1744 a f ));
00125 DATA(insert ( 1700  700 1745 i f ));
00126 DATA(insert ( 1700  701 1746 i f ));
00127 DATA(insert (  790 1700 3823 a f ));
00128 DATA(insert ( 1700  790 3824 a f ));
00129 DATA(insert ( 23    790 3811 a f ));
00130 DATA(insert ( 20    790 3812 a f ));
00131 
00132 /* Allow explicit coercions between int4 and bool */
00133 DATA(insert (   23  16  2557 e f ));
00134 DATA(insert (   16  23  2558 e f ));
00135 
00136 /*
00137  * OID category: allow implicit conversion from any integral type (including
00138  * int8, to support OID literals > 2G) to OID, as well as assignment coercion
00139  * from OID to int4 or int8.  Similarly for each OID-alias type.  Also allow
00140  * implicit coercions between OID and each OID-alias type, as well as
00141  * regproc<->regprocedure and regoper<->regoperator.  (Other coercions
00142  * between alias types must pass through OID.)  Lastly, there are implicit
00143  * casts from text and varchar to regclass, which exist mainly to support
00144  * legacy forms of nextval() and related functions.
00145  */
00146 DATA(insert (   20   26 1287 i f ));
00147 DATA(insert (   21   26  313 i f ));
00148 DATA(insert (   23   26    0 i b ));
00149 DATA(insert (   26   20 1288 a f ));
00150 DATA(insert (   26   23    0 a b ));
00151 DATA(insert (   26   24    0 i b ));
00152 DATA(insert (   24   26    0 i b ));
00153 DATA(insert (   20   24 1287 i f ));
00154 DATA(insert (   21   24  313 i f ));
00155 DATA(insert (   23   24    0 i b ));
00156 DATA(insert (   24   20 1288 a f ));
00157 DATA(insert (   24   23    0 a b ));
00158 DATA(insert (   24 2202    0 i b ));
00159 DATA(insert ( 2202   24    0 i b ));
00160 DATA(insert (   26 2202    0 i b ));
00161 DATA(insert ( 2202   26    0 i b ));
00162 DATA(insert (   20 2202 1287 i f ));
00163 DATA(insert (   21 2202  313 i f ));
00164 DATA(insert (   23 2202    0 i b ));
00165 DATA(insert ( 2202   20 1288 a f ));
00166 DATA(insert ( 2202   23    0 a b ));
00167 DATA(insert (   26 2203    0 i b ));
00168 DATA(insert ( 2203   26    0 i b ));
00169 DATA(insert (   20 2203 1287 i f ));
00170 DATA(insert (   21 2203  313 i f ));
00171 DATA(insert (   23 2203    0 i b ));
00172 DATA(insert ( 2203   20 1288 a f ));
00173 DATA(insert ( 2203   23    0 a b ));
00174 DATA(insert ( 2203 2204    0 i b ));
00175 DATA(insert ( 2204 2203    0 i b ));
00176 DATA(insert (   26 2204    0 i b ));
00177 DATA(insert ( 2204   26    0 i b ));
00178 DATA(insert (   20 2204 1287 i f ));
00179 DATA(insert (   21 2204  313 i f ));
00180 DATA(insert (   23 2204    0 i b ));
00181 DATA(insert ( 2204   20 1288 a f ));
00182 DATA(insert ( 2204   23    0 a b ));
00183 DATA(insert (   26 2205    0 i b ));
00184 DATA(insert ( 2205   26    0 i b ));
00185 DATA(insert (   20 2205 1287 i f ));
00186 DATA(insert (   21 2205  313 i f ));
00187 DATA(insert (   23 2205    0 i b ));
00188 DATA(insert ( 2205   20 1288 a f ));
00189 DATA(insert ( 2205   23    0 a b ));
00190 DATA(insert (   26 2206    0 i b ));
00191 DATA(insert ( 2206   26    0 i b ));
00192 DATA(insert (   20 2206 1287 i f ));
00193 DATA(insert (   21 2206  313 i f ));
00194 DATA(insert (   23 2206    0 i b ));
00195 DATA(insert ( 2206   20 1288 a f ));
00196 DATA(insert ( 2206   23    0 a b ));
00197 DATA(insert (   26 3734    0 i b ));
00198 DATA(insert ( 3734   26    0 i b ));
00199 DATA(insert (   20 3734 1287 i f ));
00200 DATA(insert (   21 3734  313 i f ));
00201 DATA(insert (   23 3734    0 i b ));
00202 DATA(insert ( 3734   20 1288 a f ));
00203 DATA(insert ( 3734   23    0 a b ));
00204 DATA(insert (   26 3769    0 i b ));
00205 DATA(insert ( 3769   26    0 i b ));
00206 DATA(insert (   20 3769 1287 i f ));
00207 DATA(insert (   21 3769  313 i f ));
00208 DATA(insert (   23 3769    0 i b ));
00209 DATA(insert ( 3769   20 1288 a f ));
00210 DATA(insert ( 3769   23    0 a b ));
00211 DATA(insert (   25 2205 1079 i f ));
00212 DATA(insert ( 1043 2205 1079 i f ));
00213 
00214 /*
00215  * String category
00216  */
00217 DATA(insert (   25 1042    0 i b ));
00218 DATA(insert (   25 1043    0 i b ));
00219 DATA(insert ( 1042   25  401 i f ));
00220 DATA(insert ( 1042 1043  401 i f ));
00221 DATA(insert ( 1043   25    0 i b ));
00222 DATA(insert ( 1043 1042    0 i b ));
00223 DATA(insert (   18   25  946 i f ));
00224 DATA(insert (   18 1042  860 a f ));
00225 DATA(insert (   18 1043  946 a f ));
00226 DATA(insert (   19   25  406 i f ));
00227 DATA(insert (   19 1042  408 a f ));
00228 DATA(insert (   19 1043 1401 a f ));
00229 DATA(insert (   25   18  944 a f ));
00230 DATA(insert ( 1042   18  944 a f ));
00231 DATA(insert ( 1043   18  944 a f ));
00232 DATA(insert (   25   19  407 i f ));
00233 DATA(insert ( 1042   19  409 i f ));
00234 DATA(insert ( 1043   19 1400 i f ));
00235 
00236 /* Allow explicit coercions between int4 and "char" */
00237 DATA(insert (   18   23   77 e f ));
00238 DATA(insert (   23   18   78 e f ));
00239 
00240 /* pg_node_tree can be coerced to, but not from, text */
00241 DATA(insert (  194   25    0 i b ));
00242 
00243 /*
00244  * Datetime category
00245  */
00246 DATA(insert (  702 1082 1179 a f ));
00247 DATA(insert (  702 1083 1364 a f ));
00248 DATA(insert (  702 1114 2023 i f ));
00249 DATA(insert (  702 1184 1173 i f ));
00250 DATA(insert (  703 1186 1177 i f ));
00251 DATA(insert ( 1082 1114 2024 i f ));
00252 DATA(insert ( 1082 1184 1174 i f ));
00253 DATA(insert ( 1083 1186 1370 i f ));
00254 DATA(insert ( 1083 1266 2047 i f ));
00255 DATA(insert ( 1114  702 2030 a f ));
00256 DATA(insert ( 1114 1082 2029 a f ));
00257 DATA(insert ( 1114 1083 1316 a f ));
00258 DATA(insert ( 1114 1184 2028 i f ));
00259 DATA(insert ( 1184  702 1180 a f ));
00260 DATA(insert ( 1184 1082 1178 a f ));
00261 DATA(insert ( 1184 1083 2019 a f ));
00262 DATA(insert ( 1184 1114 2027 a f ));
00263 DATA(insert ( 1184 1266 1388 a f ));
00264 DATA(insert ( 1186  703 1194 a f ));
00265 DATA(insert ( 1186 1083 1419 a f ));
00266 DATA(insert ( 1266 1083 2046 a f ));
00267 /* Cross-category casts between int4 and abstime, reltime */
00268 DATA(insert (   23  702    0 e b ));
00269 DATA(insert (  702   23    0 e b ));
00270 DATA(insert (   23  703    0 e b ));
00271 DATA(insert (  703   23    0 e b ));
00272 
00273 /*
00274  * Geometric category
00275  */
00276 DATA(insert (  601  600 1532 e f ));
00277 DATA(insert (  602  600 1533 e f ));
00278 DATA(insert (  602  604 1449 a f ));
00279 DATA(insert (  603  600 1534 e f ));
00280 DATA(insert (  603  601 1541 e f ));
00281 DATA(insert (  603  604 1448 a f ));
00282 DATA(insert (  603  718 1479 e f ));
00283 DATA(insert (  604  600 1540 e f ));
00284 DATA(insert (  604  602 1447 a f ));
00285 DATA(insert (  604  603 1446 e f ));
00286 DATA(insert (  604  718 1474 e f ));
00287 DATA(insert (  718  600 1416 e f ));
00288 DATA(insert (  718  603 1480 e f ));
00289 DATA(insert (  718  604 1544 e f ));
00290 
00291 /*
00292  * INET category
00293  */
00294 DATA(insert (  650  869    0 i b ));
00295 DATA(insert (  869  650 1715 a f ));
00296 
00297 /*
00298  * BitString category
00299  */
00300 DATA(insert ( 1560 1562    0 i b ));
00301 DATA(insert ( 1562 1560    0 i b ));
00302 /* Cross-category casts between bit and int4, int8 */
00303 DATA(insert (   20 1560 2075 e f ));
00304 DATA(insert (   23 1560 1683 e f ));
00305 DATA(insert ( 1560   20 2076 e f ));
00306 DATA(insert ( 1560   23 1684 e f ));
00307 
00308 /*
00309  * Cross-category casts to and from TEXT
00310  *
00311  * We need entries here only for a few specialized cases where the behavior
00312  * of the cast function differs from the datatype's I/O functions.  Otherwise,
00313  * parse_coerce.c will generate CoerceViaIO operations without any prompting.
00314  *
00315  * Note that the castcontext values specified here should be no stronger than
00316  * parse_coerce.c's automatic casts ('a' to text, 'e' from text) else odd
00317  * behavior will ensue when the automatic cast is applied instead of the
00318  * pg_cast entry!
00319  */
00320 DATA(insert (  650   25  730 a f ));
00321 DATA(insert (  869   25  730 a f ));
00322 DATA(insert (   16   25 2971 a f ));
00323 DATA(insert (  142   25    0 a b ));
00324 DATA(insert (   25  142 2896 e f ));
00325 
00326 /*
00327  * Cross-category casts to and from VARCHAR
00328  *
00329  * We support all the same casts as for TEXT.
00330  */
00331 DATA(insert (  650 1043  730 a f ));
00332 DATA(insert (  869 1043  730 a f ));
00333 DATA(insert (   16 1043 2971 a f ));
00334 DATA(insert (  142 1043    0 a b ));
00335 DATA(insert ( 1043  142 2896 e f ));
00336 
00337 /*
00338  * Cross-category casts to and from BPCHAR
00339  *
00340  * We support all the same casts as for TEXT.
00341  */
00342 DATA(insert (  650 1042  730 a f ));
00343 DATA(insert (  869 1042  730 a f ));
00344 DATA(insert (   16 1042 2971 a f ));
00345 DATA(insert (  142 1042    0 a b ));
00346 DATA(insert ( 1042  142 2896 e f ));
00347 
00348 /*
00349  * Length-coercion functions
00350  */
00351 DATA(insert ( 1042 1042  668 i f ));
00352 DATA(insert ( 1043 1043  669 i f ));
00353 DATA(insert ( 1083 1083 1968 i f ));
00354 DATA(insert ( 1114 1114 1961 i f ));
00355 DATA(insert ( 1184 1184 1967 i f ));
00356 DATA(insert ( 1186 1186 1200 i f ));
00357 DATA(insert ( 1266 1266 1969 i f ));
00358 DATA(insert ( 1560 1560 1685 i f ));
00359 DATA(insert ( 1562 1562 1687 i f ));
00360 DATA(insert ( 1700 1700 1703 i f ));
00361 
00362 #endif   /* PG_CAST_H */