home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre2.z / postgre2 / ref / information / built-in next >
Encoding:
Text File  |  1992-08-27  |  14.3 KB  |  468 lines

  1. .\" XXX standard disclaimer belongs here....
  2. .\" $Header: /private/postgres/ref/information/RCS/built-in,v 1.14 1992/08/03 19:26:55 frew Exp $
  3. .SS BUILT-INS 6/14/90
  4. .XA 0 "Section 3 \*- What comes with \*(PP (BUILT-INS)"
  5. .SP TYPES BUILT-INS 7/11/90
  6. .sp 2i
  7. .ps 14
  8. .ce
  9. .b "SECTION 3 \*- WHAT COMES WITH \*(PP (BUILT-INS)"
  10. .sp 3
  11. .uh "DESCRIPTION"
  12. .lp
  13. This section describes both built-in and system data types.
  14. Built-in types are required for \*(PP to run.
  15. System types are installed in every database,
  16. but are not strictly required.
  17. Built-in types are marked with asterisks in the table below.
  18. .lp
  19. Users may add new types to \*(PP using the
  20. .b "define type"
  21. command described in this manual.
  22. User-defined types are not described in this section.
  23. .sp
  24. .XA 1 "Built-in and System Types"
  25. .TS
  26. center;
  27. l l l
  28. l l c.
  29. \fBPOSTGRES Type\fP    \fBMeaning\fP    \fBRequired\fP
  30. _
  31. abstime    absolute date and time    *
  32. bool    boolean    *
  33. box    2-dimensional rectangle
  34. bytea    variable length array of bytes
  35. char    character    *
  36. char16    array of 16 characters    *
  37. cid    command identifier type    *
  38. int2    two-byte signed integer    *
  39. int28    array of 8 int2    *
  40. int4    four-byte signed integer    *
  41. float4    single-precision floating-point number    *
  42. float8    double-precision floating-point number    *
  43. lseg    2-dimensional line segment
  44. oid    object identifier type    *
  45. oid8    array of 8 oid    *
  46. path    variable-length array of lseg
  47. point    2-dimensional geometric point
  48. regproc    registered procedure    *
  49. reltime    relative date and time    *
  50. text    variable length array of characters
  51. tid    tuple identifier type    *
  52. tinterval    time interval    *
  53. uint2    two-byte unsigned integer    *
  54. uint4    four-byte unsigned integer    *
  55. xid    transaction identifier type    *
  56. .TE
  57. .lp
  58. These types all have obvious formats except for the three time types,
  59. explained in the following.
  60. .XA 1 "Syntax of date and time types"
  61. .SP "DATE AND TIME" BUILT-INS 7/11/92
  62. .uh "ABSOLUTE TIME"
  63. .lp
  64. Absolute time is specified using the following syntax:
  65. .(l
  66. .ft C
  67. Month  Day [ Hour : Minute : Second ]  Year [ Timezone ]
  68. .ft
  69.  
  70. where    Month is Jan, Feb, ..., Dec
  71.     Day is 1, 2, ..., 31
  72.     Hour is 01, 02, ..., 24
  73.     Minute is 00, 01, ..., 59
  74.     Second is 00, 01, ..., 59
  75.     Year is 1970, 1971, ..., 2038
  76. .)l
  77. .lp
  78. Valid dates are, therefore, Jan 1 00:00:00 1970 GMT to Jan 1 00:00:00 2038 GMT.
  79. As of Version 3.0, times are no longer read and written using Greenwich mean
  80. time; the input and output routines default to the local time zone.
  81. .lp
  82. The special absolute time
  83. .q now
  84. is provided as a convenience.
  85. The special absolute time ``epoch'' means Jan 1 00:00:00 1970 GMT.
  86. .uh "RELATIVE TIME"
  87. .lp
  88. Relative time is specified with the following syntax:
  89. .(l
  90. .ft C
  91. @ Quantity Unit [Direction]
  92. .ft
  93.  
  94. where     Quantity is `1', `2', ...
  95.     Unit is ``second'', ``minute'', ``hour'', ``day'', ``week'',
  96.     ``month'' (30-days), or ``year'' (365-days),
  97.     or PLURAL of these units.
  98.     Direction is ``ago''
  99. (\fBNote\fR: Valid relative times are less than or equal to 68 years)
  100. .)l
  101. .sp
  102. In addition, the special relative time ``Undefined RelTime'' is provided.
  103. .uh "TIME RANGES"
  104. .lp
  105. Time ranges are specified as:
  106. .(l
  107. .ft C
  108. [abstime, abstime]
  109. [ , abstime]
  110. [abstime, \*(lq\*(rq]
  111. [\*(lq\*(rq, \*(lq\*(rq]
  112. .ft
  113. .)l
  114. where \fIabstime\fR is a time in the absolute time format.
  115. .q ""
  116. will cause the time interval to either start or end
  117. at the least or greatest time allowable, that is, either 
  118. Jan 1 00:00:00 1902 or Jan 1 00:00:00 2038, respectively.
  119. .XA 1 "Built-in operators and functions"
  120. .SP OPERATORS BUILT-INS 7/11/89
  121. .uh OPERATORS
  122. .lp
  123. \*(PP provides a large number of built-in operators on system types.
  124. These operators are declared in the system catalog
  125. .i pg_operator .
  126. Every entry in
  127. .i pg_operator
  128. includes the object ID
  129. of the procedure that implements the operator.
  130. .lp
  131. Users may invoke operators using the operator name,
  132. as in
  133. .(l
  134. .ft C
  135. retrieve (emp.all) where emp.salary < 40000
  136. .ft
  137. .)l
  138. Alternatively,
  139. users may call the functions that implement the operators directly.
  140. In this case,
  141. the query above would be expressed as
  142. .(l
  143. .ft C
  144. retrieve (emp.all) where int4lt(emp.salary, 40000)
  145. .ft
  146. .)l
  147. .lp
  148. The rest of this section provides a list of the built-in operators
  149. and the functions that implement them.
  150. Binary operators are listed first,
  151. followed by unary operators.
  152. .sp
  153. .XA 2 "Binary operators"
  154. .ft B
  155. .ce
  156. Binary Operators
  157. .ft
  158. .lp
  159. This list was generated from the \*(PP system catalogs with the
  160. query
  161. .(b
  162. .ft C
  163. retrieve (argtype = t1.typname, o.oprname,
  164.     t0.typname, p.proname,
  165.     ltype=t1.typname, rtype=t2.typname)
  166.     from p in pg_proc, t0 in pg_type, t1 in pg_type,
  167.     t2 in pg_type, o in pg_operator
  168.     where p.prorettype = t0.oid
  169.     and RegprocToOid(o.oprcode) = p.oid
  170.     and p.pronargs = 2
  171.     and o.oprleft = t1.oid
  172.     and o.oprright = t2.oid
  173. .ft
  174. .)b
  175. The list is sorted by the built-in type name of the first operand.
  176. The
  177. .i "function prototype"
  178. column gives the return type, function name,
  179. and argument types for the procedure that implements the operator.
  180. (Note that these function prototypes are \*(PP function prototypes and they
  181. are \fBnot equivalent\fP to C function prototypes.)
  182. .TS
  183. center expand;
  184. l l c l
  185. c l l lw(2i).
  186. \fBType\fP    \fBOperator\fP    \fB\POSTGRES Function Prototype\fP    \fBOperation\fP
  187. _
  188. abstime    !\(eq    bool abstimene(abstime, abstime)    inequality
  189.     +    abstime timepl(abstime, reltime)    addition
  190.     \(mi    abstime timemi(abstime, reltime)    subtraction
  191.     <\(eq    bool abstimele(abstime, abstime)    less or equal
  192.     <?>    bool ininterval(abstime, tinterval)    abstime in tinterval?
  193.     <    bool abstimelt(abstime, abstime)    less than
  194.     \(eq    bool abstimeeq(abstime, abstime)    equality
  195.     >\(eq    bool abstimege(abstime, abstime)    greater or equal
  196.     >    bool abstimegt(abstime, abstime)    greater than
  197. _
  198. bool    \(eq    bool booleq(bool, bool)    equality
  199. _
  200. box    &&    bool box_overlap(box, box)    boxes overlap
  201.     &<    bool box_overleft(box, box)    T{
  202. box A overlaps box B,
  203. but does not extend to right
  204. of box B
  205. T}
  206.     &>    bool box_overright(box, box)    T{
  207. box A overlaps box B,
  208. but does not extend to left
  209. of box B
  210. T}
  211.     <<    bool box_left(box, box)    A is left of B
  212.     <\(eq    bool box_le(box, box)    area less or equal
  213.     <    bool box_lt(box, box)    area less than
  214.     \(eq    bool box_eq(box, box)    area equal
  215.     >\(eq    bool box_ge(box, box)    area greater or equal
  216.     >>    bool box_right(box, box)    A is right of B
  217.     >    bool box_gt(box, box)    area greater than
  218.     @    bool box_contained(box, box)    A is contained in B
  219.     ~\(eq    bool box_same(box, box)    box equality
  220.     ~    bool box_contain(box, box)    A contains B
  221. _
  222. char16    !\(eq    bool char16ne(char16, char16)    inequality
  223.     !~    bool char16regexne(char16, char16)    T{
  224. A does not match regular expression B
  225. (\*(PP uses the libc regexp calls for this
  226. operation)
  227. T}
  228.     <\(eq    bool char16le(char16, char16)    less or equal
  229.     <    bool char16lt(char16, char16)    less than
  230.     \(eq    bool char16eq(char16, char16)    equality
  231.     >\(eq    bool char16ge(char16, char16)    greater or equal
  232.     >    bool char16gt(char16, char16)    greater than
  233.     ~    bool char16regexeq(char16, char16)    T{
  234. A matches regular expression B
  235. (\*(PP uses the libc regexp calls for this
  236. operation)
  237. T}
  238. _
  239. char    !\(eq    bool charne(char, char)    inequality
  240.     *    bool charmul(char, char)    multiplication
  241.     +    bool charpl(char, char)    addition
  242.     \(mi    bool charmi(char, char)    subtraction
  243.     /    bool chardiv(char, char)    division
  244.     <\(eq    bool charle(char, char)    less or equal
  245.     <    bool charlt(char, char)    less than
  246.     \(eq    bool chareq(char, char)    equality
  247.     >\(eq    bool charge(char, char)    greater or equal
  248.     >    bool chargt(char, char)    greater than
  249. _
  250. float4    !\(eq    bool float4ne(float4, float4)    inequality
  251.     *    float4 float4mul(float4, float4)    multiplication
  252.     +    float4 float4pl(float4, float4)    addition
  253.     \(mi    float4 float4mi(float4, float4)    subtraction
  254.     /    float4 float4div(float4, float4)    division
  255.     <\(eq    bool float4le(float4, float4)    less or equal
  256.     <    bool float4lt(float4, float4)    less than
  257.     \(eq    bool float4eq(float4, float4)    equality
  258.     >\(eq    bool float4ge(float4, float4)    greater or equal
  259.     >    bool float4gt(float4, float4)    greater than
  260. _
  261. float8    !\(eq    bool float8ne(float8, float8)    inequality
  262.     *    float8 float8mul(float8, float8)    multiplication
  263.     +    float8 float8pl(float8, float8)    addition
  264.     \(mi    float8 float8mi(float8, float8)    subtraction
  265.     /    float8 float8div(float8, float8)    division
  266.     <\(eq    bool float8le(float8, float8)    less or equal
  267.     <    bool float8lt(float8, float8)    less than1
  268.     \(eq    bool float8eq(float8, float8)    equality
  269.     >\(eq    bool float8ge(float8, float8)    greater or equal
  270.     >    bool float8gt(float8, float8)    greater than
  271.     ^    float8 dpow(float8, float8)    exponentiation
  272. _
  273. int2    !\(eq    bool int2ne(int2, int2)    inequality
  274.     !\(eq    int4 int24ne(int2, int4)    inequality
  275.     %    int2 int2mod(int2, int2)    modulus
  276.     %    int4 int24mod(int2, int4)    modulus
  277.     *    int2 int2mul(int2, int2)    multiplication
  278.     *    int4 int24mul(int2, int4)    multiplication
  279.     +    int2 int2pl(int2, int2)    addition
  280.     +    int4 int24pl(int2, int4)    addition
  281.     \(mi    int2 int2mi(int2, int2)    subtraction
  282.     \(mi    int4 int24mi(int2, int4)    subtraction
  283.     /    int2 int2div(int2, int2)    division
  284.     /    int4 int24div(int2, int4)    division
  285.     <\(eq    bool int2le(int2, int2)    less or equal
  286.     <\(eq    int4 int24le(int2, int4)    less or equal
  287.     <    bool int2lt(int2, int2)    less than
  288.     <    int4 int24lt(int2, int4)    less than
  289.     \(eq    bool int2eq(int2, int2)    equality
  290.     \(eq    int4 int24eq(int2, int4)    equality
  291.     >\(eq    bool int2ge(int2, int2)    greater or equal
  292.     >\(eq    int4 int24ge(int2, int4)    greater or equal
  293.     >    bool int2gt(int2, int2)    greater than
  294.     >    int4 int24gt(int2, int4)    greater than
  295.         int2 int2inc(int2)    increment
  296. _
  297. int4    !!\(eq    bool int4notin(int4, char16)    T{
  298. This is the relational ``not in'' operator,
  299. and is not intended for public use.
  300. T}
  301.     !\(eq    bool int4ne(int4, int4)    inequality
  302.     !\(eq    int4 int42ne(int4, int2)    inequality
  303.     %    int4 int42mod(int4, int2)    modulus
  304.     %    int4 int4mod(int4, int4)    modulus
  305.     *    int4 int42mul(int4, int2)    multiplication
  306.     *    int4 int4mul(int4, int4)    multiplication
  307.     +    int4 int42pl(int4, int2)    addition
  308.     +    int4 int4pl(int4, int4)    addition
  309.     \(mi    int4 int42mi(int4, int2)    subtraction
  310.     \(mi    int4 int4mi(int4, int4)    subtraction
  311.     /    int4 int42div(int4, int2)    division
  312.     /    int4 int4div(int4, int4)    division
  313.     <\(eq    bool int4le(int4, int4)    less or equal
  314.     <\(eq    int4 int42le(int4, int2)    less or equal
  315.     <    bool int4lt(int4, int4)    less than
  316.     <    int4 int42lt(int4, int2)    less than
  317.     \(eq    bool int4eq(int4, int4)    equality
  318.     \(eq    int4 int42eq(int4, int2)    equality
  319.     >\(eq    bool int4ge(int4, int4)    greater or equal
  320.     >\(eq    int4 int42ge(int4, int2)    greater or equal
  321.     >    bool int4gt(int4, int4)    greater than
  322.     >    int4 int42lt(int4, int2)    less than
  323.         int4 int4inc(int4)    increment
  324. _
  325. oid    !!\(eq    bool oidnotin(oid, char16)    T{
  326. This is the relational ``not in'' operator,
  327. and is not intended for public use.
  328. T}
  329.     !\(eq    bool oidneq(oid, oid)    inequality
  330.     !\(eq    bool oidneq(oid, regproc)    inequality
  331.     <\(eq    bool int4le(oid, oid)    less or equal
  332.     <    bool int4lt(oid, oid)    less than
  333.     \(eq    bool oideq(oid, oid)    equality
  334.     \(eq    bool oideq(oid, regproc)    equality
  335.     >\(eq    bool int4ge(oid, oid)    greater or equal
  336.     >    bool int4gt(oid, oid)    greater than
  337. _
  338. point    !<    bool point_left(point, point)    A is left of B
  339.     !>    bool point_right(point, point)    A is right of B
  340.     !^    bool point_above(point, point)    A is above B
  341.     !|    bool point_below(point, point)    A is below B
  342.     \(eq|\(eq    bool point_eq(point, point)    equality
  343.     --->    bool on_pb(point, box)    point inside box
  344.     ---`    bool on_ppath(point, path)    point on path
  345.     <--->    int4 pointdist(point, point)    distance between points
  346. _
  347. polygon    &&    bool poly_overlap(polygon, polygon)    polygons overlap
  348.     &<    bool poly_overleft(polygon, polygon)    T{
  349. A overlaps B but does not extend to
  350. right of B
  351. T}
  352.     &>    bool poly_overright(polygon, polygon)    T{
  353. A overlaps B but does not extend to
  354. left of B
  355. T}
  356.     <<    bool poly_left(polygon, polygon)    A is left of B
  357.     >>    bool poly_right(polygon, polygon)    A is right of B
  358.     @    bool poly_contained(polygon, polygon)    A is contained by B
  359.     ~\(eq    bool poly_same(polygon, polygon)    equality
  360.     ~    bool poly_contain(polygon, polygon)    A contains B
  361. _
  362. regproc    !\(eq    bool oidneq(regproc, oid)    inequality
  363.     \(eq    bool oideq(regproc, oid)    equality
  364. _
  365. reltime    !\(eq    bool reltimene(reltime, reltime)    inequality
  366.     <\(eq    bool reltimele(reltime, reltime)    less or equal
  367.     <    bool reltimelt(reltime, reltime)    less than
  368.     \(eq    bool reltimeeq(reltime, reltime)    equality
  369.     >\(eq    bool reltimege(reltime, reltime)    greater or equal
  370.     >    bool reltimegt(reltime, reltime)    greater than
  371. _
  372. text    !\(eq    bool textne(text, text)    inequality
  373.     !~    bool textregexne(text, text)    T{
  374. A does not contain the regular expression B.
  375. \*(PP uses the libc regexp interface for this
  376. operator.
  377. T}
  378.     <\(eq    bool text_le(text, text)    less or equal
  379.     <    bool text_lt(text, text)    less than
  380.     \(eq    bool texteq(text, text)    equality
  381.     >\(eq    bool text_ge(text, text)    greater or equal
  382.     >    bool text_gt(text, text)    greater than
  383.     ~    bool textregexeq(text, text)    T{
  384. A contains the regular expression B.
  385. \*(PP uses the libc regexp interface for this
  386. operator.
  387. T}
  388. _
  389. tinterval    #!\(eq    bool intervallenne(tinterval, reltime)    T{
  390. interval length not equal to reltime.
  391. T}
  392.     #<\(eq    bool intervallenle(tinterval, reltime)    T{
  393. interval length less or equal reltime
  394. T}
  395.     #<    bool intervallenlt(tinterval, reltime)    T{
  396. interval length less than reltime
  397. T}
  398.     #\(eq    bool intervalleneq(tinterval, reltime)    T{
  399. interval length not equal to reltime
  400. T}
  401.     #>\(eq    bool intervallenge(tinterval, reltime)    T{
  402. interval length greater or equal reltime
  403. T}
  404.     #>    bool intervallengt(tinterval, reltime)    T{
  405. interval length greater than reltime
  406. T}
  407.     &&    bool intervalov(tinterval, tinterval)    intervals overlap
  408.     <<    bool intervalct(tinterval, tinterval)    A contains B
  409.     \(eq    bool intervaleq(tinterval, tinterval)    equality
  410. .TE
  411. .sp
  412. .sp
  413. .XA 2 "Unary operators"
  414. .ft B
  415. .ce
  416. Unary Operators
  417. .ft
  418. .lp
  419. The tables below give right and left unary operators.
  420. Left unary operators have the operator precede the operand;
  421. right unary operators have the operator follow the operand.
  422. .sp
  423. .sp
  424. .ft B
  425. .ce
  426. Right Unary Operators
  427. .ft
  428. .TS
  429. center expand;
  430. l l c l
  431. c l l lw(2i).
  432. \fBType\fP    \fBOperator\fP    \fB\POSTGRES Function Prototype\fP    \fBOperation\fP
  433. _
  434. float8    %    float8 dround(float8)    round to nearest integer
  435. .TE
  436. .sp
  437. .ft B
  438. .ce
  439. Left Unary Operators
  440. .ft
  441. .TS
  442. center expand;
  443. l l c l
  444. c l l lw(2i).
  445. \fBType\fP    \fBOperator\fP    \fB\POSTGRES Function Prototype\fP    \fBOperation\fP
  446. _
  447. box    @@    point box_center(box)    center of box
  448. _
  449. float4    @    float4 float4abs(float4)    absolute value
  450. _
  451. float8    @    float8 float8abs(float8)    absolute value
  452.     %    float8 dtrunc(float8)    truncate to integer
  453.     |/    float8 dsqrt(float8)    square root
  454.     ||/    float8 dcbrt(float8)    cube root
  455.     :    float8 dexp(float8)    exponential function
  456.     ;    float8 dlog1(float8)    natural logarithm
  457. _
  458. tinterval    |    abstime intervalstart(tinterval)    start of interval
  459. .TE
  460. .uh "SEE ALSO"
  461. .lp
  462. For examples on specifying literals of built-in types, see postquel(commands).
  463. .uh BUGS
  464. .lp
  465. The lists of types, functions, and operators are accurate only for
  466. Version \*(PV.  The lists will be incomplete and contain extraneous
  467. entries in future versions of \*(PP.
  468.