pg_cast.h 12 KB

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