PostgreSQL Source Code  git master
pg_cast.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_cast.h
4  * definition of the system "type casts" relation (pg_cast)
5  * along with the relation's initial contents.
6  *
7  * As of Postgres 8.0, pg_cast describes not only type coercion functions
8  * but also length coercion functions.
9  *
10  *
11  * Copyright (c) 2002-2017, PostgreSQL Global Development Group
12  *
13  * src/include/catalog/pg_cast.h
14  *
15  * NOTES
16  * the genbki.pl script reads this file and generates .bki
17  * information from the DATA() statements.
18  *
19  *-------------------------------------------------------------------------
20  */
21 #ifndef PG_CAST_H
22 #define PG_CAST_H
23 
24 #include "catalog/genbki.h"
25 
26 /* ----------------
27  * pg_cast definition. cpp turns this into
28  * typedef struct FormData_pg_cast
29  * ----------------
30  */
31 #define CastRelationId 2605
32 
33 CATALOG(pg_cast,2605)
34 {
35  Oid castsource; /* source datatype for cast */
36  Oid casttarget; /* destination datatype for cast */
37  Oid castfunc; /* cast function; 0 = binary coercible */
38  char castcontext; /* contexts in which cast can be used */
39  char castmethod; /* cast method */
41 
43 
44 /*
45  * The allowable values for pg_cast.castcontext are specified by this enum.
46  * Since castcontext is stored as a "char", we use ASCII codes for human
47  * convenience in reading the table. Note that internally to the backend,
48  * these values are converted to the CoercionContext enum (see primnodes.h),
49  * which is defined to sort in a convenient order; the ASCII codes don't
50  * have to sort in any special order.
51  */
52 
53 typedef enum CoercionCodes
54 {
55  COERCION_CODE_IMPLICIT = 'i', /* coercion in context of expression */
56  COERCION_CODE_ASSIGNMENT = 'a', /* coercion in context of assignment */
57  COERCION_CODE_EXPLICIT = 'e' /* explicit cast operation */
59 
60 /*
61  * The allowable values for pg_cast.castmethod are specified by this enum.
62  * Since castmethod is stored as a "char", we use ASCII codes for human
63  * convenience in reading the table.
64  */
65 typedef enum CoercionMethod
66 {
67  COERCION_METHOD_FUNCTION = 'f', /* use a function */
68  COERCION_METHOD_BINARY = 'b', /* types are binary-compatible */
69  COERCION_METHOD_INOUT = 'i' /* use input/output functions */
71 
72 
73 /* ----------------
74  * compiler constants for pg_cast
75  * ----------------
76  */
77 #define Natts_pg_cast 5
78 #define Anum_pg_cast_castsource 1
79 #define Anum_pg_cast_casttarget 2
80 #define Anum_pg_cast_castfunc 3
81 #define Anum_pg_cast_castcontext 4
82 #define Anum_pg_cast_castmethod 5
83 
84 /* ----------------
85  * initial contents of pg_cast
86  *
87  * Note: this table has OIDs, but we don't bother to assign them manually,
88  * since nothing needs to know the specific OID of any built-in cast.
89  * ----------------
90  */
91 
92 /*
93  * Numeric category: implicit casts are allowed in the direction
94  * int2->int4->int8->numeric->float4->float8, while casts in the
95  * reverse direction are assignment-only.
96  */
97 DATA(insert ( 20 21 714 a f ));
98 DATA(insert ( 20 23 480 a f ));
99 DATA(insert ( 20 700 652 i f ));
100 DATA(insert ( 20 701 482 i f ));
101 DATA(insert ( 20 1700 1781 i f ));
102 DATA(insert ( 21 20 754 i f ));
103 DATA(insert ( 21 23 313 i f ));
104 DATA(insert ( 21 700 236 i f ));
105 DATA(insert ( 21 701 235 i f ));
106 DATA(insert ( 21 1700 1782 i f ));
107 DATA(insert ( 23 20 481 i f ));
108 DATA(insert ( 23 21 314 a f ));
109 DATA(insert ( 23 700 318 i f ));
110 DATA(insert ( 23 701 316 i f ));
111 DATA(insert ( 23 1700 1740 i f ));
112 DATA(insert ( 700 20 653 a f ));
113 DATA(insert ( 700 21 238 a f ));
114 DATA(insert ( 700 23 319 a f ));
115 DATA(insert ( 700 701 311 i f ));
116 DATA(insert ( 700 1700 1742 a f ));
117 DATA(insert ( 701 20 483 a f ));
118 DATA(insert ( 701 21 237 a f ));
119 DATA(insert ( 701 23 317 a f ));
120 DATA(insert ( 701 700 312 a f ));
121 DATA(insert ( 701 1700 1743 a f ));
122 DATA(insert ( 1700 20 1779 a f ));
123 DATA(insert ( 1700 21 1783 a f ));
124 DATA(insert ( 1700 23 1744 a f ));
125 DATA(insert ( 1700 700 1745 i f ));
126 DATA(insert ( 1700 701 1746 i f ));
127 DATA(insert ( 790 1700 3823 a f ));
128 DATA(insert ( 1700 790 3824 a f ));
129 DATA(insert ( 23 790 3811 a f ));
130 DATA(insert ( 20 790 3812 a f ));
131 
132 /* Allow explicit coercions between int4 and bool */
133 DATA(insert ( 23 16 2557 e f ));
134 DATA(insert ( 16 23 2558 e f ));
135 
136 /*
137  * OID category: allow implicit conversion from any integral type (including
138  * int8, to support OID literals > 2G) to OID, as well as assignment coercion
139  * from OID to int4 or int8. Similarly for each OID-alias type. Also allow
140  * implicit coercions between OID and each OID-alias type, as well as
141  * regproc<->regprocedure and regoper<->regoperator. (Other coercions
142  * between alias types must pass through OID.) Lastly, there are implicit
143  * casts from text and varchar to regclass, which exist mainly to support
144  * legacy forms of nextval() and related functions.
145  */
146 DATA(insert ( 20 26 1287 i f ));
147 DATA(insert ( 21 26 313 i f ));
148 DATA(insert ( 23 26 0 i b ));
149 DATA(insert ( 26 20 1288 a f ));
150 DATA(insert ( 26 23 0 a b ));
151 DATA(insert ( 26 24 0 i b ));
152 DATA(insert ( 24 26 0 i b ));
153 DATA(insert ( 20 24 1287 i f ));
154 DATA(insert ( 21 24 313 i f ));
155 DATA(insert ( 23 24 0 i b ));
156 DATA(insert ( 24 20 1288 a f ));
157 DATA(insert ( 24 23 0 a b ));
158 DATA(insert ( 24 2202 0 i b ));
159 DATA(insert ( 2202 24 0 i b ));
160 DATA(insert ( 26 2202 0 i b ));
161 DATA(insert ( 2202 26 0 i b ));
162 DATA(insert ( 20 2202 1287 i f ));
163 DATA(insert ( 21 2202 313 i f ));
164 DATA(insert ( 23 2202 0 i b ));
165 DATA(insert ( 2202 20 1288 a f ));
166 DATA(insert ( 2202 23 0 a b ));
167 DATA(insert ( 26 2203 0 i b ));
168 DATA(insert ( 2203 26 0 i b ));
169 DATA(insert ( 20 2203 1287 i f ));
170 DATA(insert ( 21 2203 313 i f ));
171 DATA(insert ( 23 2203 0 i b ));
172 DATA(insert ( 2203 20 1288 a f ));
173 DATA(insert ( 2203 23 0 a b ));
174 DATA(insert ( 2203 2204 0 i b ));
175 DATA(insert ( 2204 2203 0 i b ));
176 DATA(insert ( 26 2204 0 i b ));
177 DATA(insert ( 2204 26 0 i b ));
178 DATA(insert ( 20 2204 1287 i f ));
179 DATA(insert ( 21 2204 313 i f ));
180 DATA(insert ( 23 2204 0 i b ));
181 DATA(insert ( 2204 20 1288 a f ));
182 DATA(insert ( 2204 23 0 a b ));
183 DATA(insert ( 26 2205 0 i b ));
184 DATA(insert ( 2205 26 0 i b ));
185 DATA(insert ( 20 2205 1287 i f ));
186 DATA(insert ( 21 2205 313 i f ));
187 DATA(insert ( 23 2205 0 i b ));
188 DATA(insert ( 2205 20 1288 a f ));
189 DATA(insert ( 2205 23 0 a b ));
190 DATA(insert ( 26 2206 0 i b ));
191 DATA(insert ( 2206 26 0 i b ));
192 DATA(insert ( 20 2206 1287 i f ));
193 DATA(insert ( 21 2206 313 i f ));
194 DATA(insert ( 23 2206 0 i b ));
195 DATA(insert ( 2206 20 1288 a f ));
196 DATA(insert ( 2206 23 0 a b ));
197 DATA(insert ( 26 3734 0 i b ));
198 DATA(insert ( 3734 26 0 i b ));
199 DATA(insert ( 20 3734 1287 i f ));
200 DATA(insert ( 21 3734 313 i f ));
201 DATA(insert ( 23 3734 0 i b ));
202 DATA(insert ( 3734 20 1288 a f ));
203 DATA(insert ( 3734 23 0 a b ));
204 DATA(insert ( 26 3769 0 i b ));
205 DATA(insert ( 3769 26 0 i b ));
206 DATA(insert ( 20 3769 1287 i f ));
207 DATA(insert ( 21 3769 313 i f ));
208 DATA(insert ( 23 3769 0 i b ));
209 DATA(insert ( 3769 20 1288 a f ));
210 DATA(insert ( 3769 23 0 a b ));
211 DATA(insert ( 25 2205 1079 i f ));
212 DATA(insert ( 1043 2205 1079 i f ));
213 DATA(insert ( 26 4096 0 i b ));
214 DATA(insert ( 4096 26 0 i b ));
215 DATA(insert ( 20 4096 1287 i f ));
216 DATA(insert ( 21 4096 313 i f ));
217 DATA(insert ( 23 4096 0 i b ));
218 DATA(insert ( 4096 20 1288 a f ));
219 DATA(insert ( 4096 23 0 a b ));
220 DATA(insert ( 26 4089 0 i b ));
221 DATA(insert ( 4089 26 0 i b ));
222 DATA(insert ( 20 4089 1287 i f ));
223 DATA(insert ( 21 4089 313 i f ));
224 DATA(insert ( 23 4089 0 i b ));
225 DATA(insert ( 4089 20 1288 a f ));
226 DATA(insert ( 4089 23 0 a b ));
227 
228 /*
229  * String category
230  */
231 DATA(insert ( 25 1042 0 i b ));
232 DATA(insert ( 25 1043 0 i b ));
233 DATA(insert ( 1042 25 401 i f ));
234 DATA(insert ( 1042 1043 401 i f ));
235 DATA(insert ( 1043 25 0 i b ));
236 DATA(insert ( 1043 1042 0 i b ));
237 DATA(insert ( 18 25 946 i f ));
238 DATA(insert ( 18 1042 860 a f ));
239 DATA(insert ( 18 1043 946 a f ));
240 DATA(insert ( 19 25 406 i f ));
241 DATA(insert ( 19 1042 408 a f ));
242 DATA(insert ( 19 1043 1401 a f ));
243 DATA(insert ( 25 18 944 a f ));
244 DATA(insert ( 1042 18 944 a f ));
245 DATA(insert ( 1043 18 944 a f ));
246 DATA(insert ( 25 19 407 i f ));
247 DATA(insert ( 1042 19 409 i f ));
248 DATA(insert ( 1043 19 1400 i f ));
249 
250 /* Allow explicit coercions between int4 and "char" */
251 DATA(insert ( 18 23 77 e f ));
252 DATA(insert ( 23 18 78 e f ));
253 
254 /* pg_node_tree can be coerced to, but not from, text */
255 DATA(insert ( 194 25 0 i b ));
256 
257 /* pg_ndistinct can be coerced to, but not from, bytea and text */
258 DATA(insert ( 3361 17 0 i b ));
259 DATA(insert ( 3361 25 0 i i ));
260 
261 /* pg_dependencies can be coerced to, but not from, bytea and text */
262 DATA(insert ( 3402 17 0 i b ));
263 DATA(insert ( 3402 25 0 i i ));
264 
265 /*
266  * Datetime category
267  */
268 DATA(insert ( 702 1082 1179 a f ));
269 DATA(insert ( 702 1083 1364 a f ));
270 DATA(insert ( 702 1114 2023 i f ));
271 DATA(insert ( 702 1184 1173 i f ));
272 DATA(insert ( 703 1186 1177 i f ));
273 DATA(insert ( 1082 1114 2024 i f ));
274 DATA(insert ( 1082 1184 1174 i f ));
275 DATA(insert ( 1083 1186 1370 i f ));
276 DATA(insert ( 1083 1266 2047 i f ));
277 DATA(insert ( 1114 702 2030 a f ));
278 DATA(insert ( 1114 1082 2029 a f ));
279 DATA(insert ( 1114 1083 1316 a f ));
280 DATA(insert ( 1114 1184 2028 i f ));
281 DATA(insert ( 1184 702 1180 a f ));
282 DATA(insert ( 1184 1082 1178 a f ));
283 DATA(insert ( 1184 1083 2019 a f ));
284 DATA(insert ( 1184 1114 2027 a f ));
285 DATA(insert ( 1184 1266 1388 a f ));
286 DATA(insert ( 1186 703 1194 a f ));
287 DATA(insert ( 1186 1083 1419 a f ));
288 DATA(insert ( 1266 1083 2046 a f ));
289 /* Cross-category casts between int4 and abstime, reltime */
290 DATA(insert ( 23 702 0 e b ));
291 DATA(insert ( 702 23 0 e b ));
292 DATA(insert ( 23 703 0 e b ));
293 DATA(insert ( 703 23 0 e b ));
294 
295 /*
296  * Geometric category
297  */
298 DATA(insert ( 600 603 4091 a f ));
299 DATA(insert ( 601 600 1532 e f ));
300 DATA(insert ( 602 600 1533 e f ));
301 DATA(insert ( 602 604 1449 a f ));
302 DATA(insert ( 603 600 1534 e f ));
303 DATA(insert ( 603 601 1541 e f ));
304 DATA(insert ( 603 604 1448 a f ));
305 DATA(insert ( 603 718 1479 e f ));
306 DATA(insert ( 604 600 1540 e f ));
307 DATA(insert ( 604 602 1447 a f ));
308 DATA(insert ( 604 603 1446 e f ));
309 DATA(insert ( 604 718 1474 e f ));
310 DATA(insert ( 718 600 1416 e f ));
311 DATA(insert ( 718 603 1480 e f ));
312 DATA(insert ( 718 604 1544 e f ));
313 
314 /*
315  * MAC address category
316  */
317 DATA(insert ( 829 774 4123 i f ));
318 DATA(insert ( 774 829 4124 i f ));
319 
320 /*
321  * INET category
322  */
323 DATA(insert ( 650 869 0 i b ));
324 DATA(insert ( 869 650 1715 a f ));
325 
326 /*
327  * BitString category
328  */
329 DATA(insert ( 1560 1562 0 i b ));
330 DATA(insert ( 1562 1560 0 i b ));
331 /* Cross-category casts between bit and int4, int8 */
332 DATA(insert ( 20 1560 2075 e f ));
333 DATA(insert ( 23 1560 1683 e f ));
334 DATA(insert ( 1560 20 2076 e f ));
335 DATA(insert ( 1560 23 1684 e f ));
336 
337 /*
338  * Cross-category casts to and from TEXT
339  *
340  * We need entries here only for a few specialized cases where the behavior
341  * of the cast function differs from the datatype's I/O functions. Otherwise,
342  * parse_coerce.c will generate CoerceViaIO operations without any prompting.
343  *
344  * Note that the castcontext values specified here should be no stronger than
345  * parse_coerce.c's automatic casts ('a' to text, 'e' from text) else odd
346  * behavior will ensue when the automatic cast is applied instead of the
347  * pg_cast entry!
348  */
349 DATA(insert ( 650 25 730 a f ));
350 DATA(insert ( 869 25 730 a f ));
351 DATA(insert ( 16 25 2971 a f ));
352 DATA(insert ( 142 25 0 a b ));
353 DATA(insert ( 25 142 2896 e f ));
354 
355 /*
356  * Cross-category casts to and from VARCHAR
357  *
358  * We support all the same casts as for TEXT.
359  */
360 DATA(insert ( 650 1043 730 a f ));
361 DATA(insert ( 869 1043 730 a f ));
362 DATA(insert ( 16 1043 2971 a f ));
363 DATA(insert ( 142 1043 0 a b ));
364 DATA(insert ( 1043 142 2896 e f ));
365 
366 /*
367  * Cross-category casts to and from BPCHAR
368  *
369  * We support all the same casts as for TEXT.
370  */
371 DATA(insert ( 650 1042 730 a f ));
372 DATA(insert ( 869 1042 730 a f ));
373 DATA(insert ( 16 1042 2971 a f ));
374 DATA(insert ( 142 1042 0 a b ));
375 DATA(insert ( 1042 142 2896 e f ));
376 
377 /*
378  * Length-coercion functions
379  */
380 DATA(insert ( 1042 1042 668 i f ));
381 DATA(insert ( 1043 1043 669 i f ));
382 DATA(insert ( 1083 1083 1968 i f ));
383 DATA(insert ( 1114 1114 1961 i f ));
384 DATA(insert ( 1184 1184 1967 i f ));
385 DATA(insert ( 1186 1186 1200 i f ));
386 DATA(insert ( 1266 1266 1969 i f ));
387 DATA(insert ( 1560 1560 1685 i f ));
388 DATA(insert ( 1562 1562 1687 i f ));
389 DATA(insert ( 1700 1700 1703 i f ));
390 
391 /* json to/from jsonb */
392 DATA(insert ( 114 3802 0 a i ));
393 DATA(insert ( 3802 114 0 a i ));
394 
395 #endif /* PG_CAST_H */
unsigned int Oid
Definition: postgres_ext.h:31
CoercionMethod
Definition: pg_cast.h:65
FormData_pg_cast
Definition: pg_cast.h:40
CoercionCodes
Definition: pg_cast.h:53
CATALOG(pg_cast, 2605)
Definition: pg_cast.h:33
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:42
DATA(insert(20 21 714 a f))
e
Definition: preproc-init.c:82
int i