func.sgml 21.1 KB
Newer Older
1 2
 <Chapter Id="functions">
  <Title id="functions-title">Functions</Title>
3

4 5 6 7 8
  <Abstract>
   <Para>
    Describes the built-in functions available in <ProductName>Postgres</ProductName>.
   </Para>
  </Abstract>
9

10 11 12 13 14
  <Para>
   Many data types have functions available for conversion to other related types.
   In addition, there are some type-specific functions. Some functions are also
   available through operators and may be documented as operators only.
  </Para>
15

16 17
  <sect1>
   <title id="sql-funcs">SQL Functions</title>
18

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
   <para>
    <quote><acronym>SQL</acronym> functions</quote> are constructs
    defined by the <acronym>SQL92</acronym> standard which have
    function-like syntax but which can not be implemented as simple
    functions. 
   </para>

   <para>
    <TABLE TOCENTRY="1">
     <TITLE>SQL Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> COALESCE(<replaceable class="parameter">list</replaceable>) </ENTRY>
	<ENTRY> non-NULL </ENTRY>
	<ENTRY> return first non-NULL value in list </ENTRY>
	<ENTRY> COALESCE(<replaceable class="parameter">c1</replaceable>, <replaceable class="parameter">c2</replaceable> + 5, 0) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> IFNULL(<replaceable
	  class="parameter">input</replaceable>,<replaceable> class="parameter">non-NULL substitute</replaceable>) </ENTRY>
	<ENTRY> non-NULL </ENTRY>
	<ENTRY> return second argument if first is NULL </ENTRY>
	<ENTRY> IFNULL(<replaceable class="parameter">c1</replaceable>, 'N/A')</ENTRY>
       </ROW>
       <ROW>
	<ENTRY> CASE(WHEN <replaceable class="parameter">expr</replaceable> THEN <replaceable class="parameter">expr</replaceable> [...] ELSE <replaceable class="parameter">expr</replaceable> ) </ENTRY>
	<ENTRY> <replaceable class="parameter">expr</replaceable> </ENTRY>
	<ENTRY> return expression for first true clause </ENTRY>
	<ENTRY> CASE(WHEN <replaceable class="parameter">c1</replaceable> = 1 THEN 'match' ELSE 'no match') </ENTRY>
       </ROW>
      </tbody>
     </tgroup>
    </table>
   </para>
  </sect1>

  <sect1>
   <title id="math-funcs">Mathematical Functions</title>

   <Para>
    <TABLE TOCENTRY="1">
     <TITLE>Mathematical Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> dexp(float8) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> raise e to the specified exponent </ENTRY>
	<ENTRY> dexp(2.0) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> dpow(float8,float8) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> raise a number to the specified exponent </ENTRY>
	<ENTRY> dpow(2.0, 16.0) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> float(int) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> convert integer to floating point </ENTRY>
	<ENTRY> float(2) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> float4(int) </ENTRY>
	<ENTRY> float4 </ENTRY>
	<ENTRY> convert integer to floating point </ENTRY>
	<ENTRY> float4(2) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> integer(float) </ENTRY>
	<ENTRY> int </ENTRY>
	<ENTRY> convert floating point to integer </ENTRY>
	<ENTRY> integer(2.0) </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
  </sect1>
115

116 117
  <sect1>
   <title>String Functions</title>
118

119 120 121 122 123 124
   <Para>
    SQL92 defines string functions with specific syntax. Some of these
    are implemented using other <ProductName>Postgres</ProductName> functions.
    The supported string types for <acronym>SQL92</acronym> are
    <type>char</type>, <type>varchar</type>, and <type>text</type>.
   </Para>
125

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
   <Para>
    <TABLE TOCENTRY="1">
     <TITLE><Acronym>SQL92</Acronym> String Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> char_length(string) </ENTRY>
	<ENTRY> int4 </ENTRY>
	<ENTRY> length of string </ENTRY>
	<ENTRY> char_length('jose') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> character_length(string) </ENTRY>
	<ENTRY> int4 </ENTRY>
	<ENTRY> length of string </ENTRY>
	<ENTRY> char_length('jose') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> lower(string) </ENTRY>
	<ENTRY> string </ENTRY>
	<ENTRY> convert string to lower case </ENTRY>
	<ENTRY> lower('TOM') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> octet_length(string) </ENTRY>
	<ENTRY> int4 </ENTRY>
	<ENTRY> storage length of string </ENTRY>
	<ENTRY> octet_length('jose') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> position(string in string) </ENTRY>
	<ENTRY> int4 </ENTRY>
	<ENTRY> location of specified substring </ENTRY>
	<ENTRY> position('o' in 'Tom') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> substring(string [from int] [for int]) </ENTRY>
	<ENTRY> string </ENTRY>
	<ENTRY> extract specified substring </ENTRY>
	<ENTRY> substring('Tom' from 2 for 2) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> trim([leading|trailing|both] [string] from string) </ENTRY>
	<ENTRY> string </ENTRY>
	<ENTRY> trim characters from string </ENTRY>
	<ENTRY> trim(both 'x' from 'xTomx') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> upper(text) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> convert text to upper case </ENTRY>
	<ENTRY> upper('tom') </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
191

192 193 194 195
   <Para>
    Many additional string functions are available for text, varchar(), and char() types.
    Some are used internally to implement the SQL92 string functions listed above.
   </Para>
196

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
   <Para>
    <TABLE TOCENTRY="1">
     <TITLE>String Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> char(text) </ENTRY>
	<ENTRY> char </ENTRY>
	<ENTRY> convert text to char type </ENTRY>
	<ENTRY> char('text string') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> char(varchar) </ENTRY>
	<ENTRY> char </ENTRY>
	<ENTRY> convert varchar to char type </ENTRY>
	<ENTRY> char(varchar 'varchar string') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> initcap(text) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> first letter of each word to upper case </ENTRY>
	<ENTRY> initcap('thomas') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> lpad(text,int,text) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> left pad string to specified length </ENTRY>
	<ENTRY> lpad('hi',4,'??') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> ltrim(text,text) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> left trim characters from text </ENTRY>
	<ENTRY> ltrim('xxxxtrim','x') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> textpos(text,text) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> locate specified substring </ENTRY>
	<ENTRY> position('high','ig') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> rpad(text,int,text) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> right pad string to specified length </ENTRY>
	<ENTRY> rpad('hi',4,'x') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> rtrim(text,text) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> right trim characters from text </ENTRY>
	<ENTRY> rtrim('trimxxxx','x') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> substr(text,int[,int]) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> extract specified substring </ENTRY>
	<ENTRY> substr('hi there',3,5) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> text(char) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> convert char to text type </ENTRY>
	<ENTRY> text('char string') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> text(varchar) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> convert varchar to text type </ENTRY>
	<ENTRY> text(varchar 'varchar string') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> translate(text,from,to) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> convert character in string </ENTRY>
	<ENTRY> translate('12345', '1', 'a') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> varchar(char) </ENTRY>
	<ENTRY> varchar </ENTRY>
	<ENTRY> convert char to varchar type </ENTRY>
	<ENTRY> varchar('char string') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> varchar(text) </ENTRY>
	<ENTRY> varchar </ENTRY>
	<ENTRY> convert text to varchar type </ENTRY>
	<ENTRY> varchar('text string') </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
298

299 300 301 302
   <para>
    Most functions explicitly defined for text will work for char() and varchar() arguments.
   </para>
  </sect1>
303

304 305
  <sect1>
   <title>Date/Time Functions</title>
306

307 308 309 310
   <para>
    The date/time functions provide a powerful set of tools
    for manipulating various date/time types.
   </para>
311

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
   <Para>
    <TABLE TOCENTRY="1">
     <TITLE>Date/Time Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> abstime(datetime) </ENTRY>
	<ENTRY> abstime </ENTRY>
	<ENTRY> convert to abstime </ENTRY>
	<ENTRY> abstime('now'::datetime) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> age(datetime,datetime) </ENTRY>
	<ENTRY> timespan </ENTRY>
	<ENTRY> span preserving months and years </ENTRY>
	<ENTRY> age('now','1957-06-13'::datetime) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> datetime(abstime) </ENTRY>
	<ENTRY> datetime </ENTRY>
	<ENTRY> convert to datetime </ENTRY>
	<ENTRY> datetime('now'::abstime) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> datetime(date) </ENTRY>
	<ENTRY> datetime </ENTRY>
	<ENTRY> convert to datetime </ENTRY>
	<ENTRY> datetime('today'::date) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> datetime(date,time) </ENTRY>
	<ENTRY> datetime </ENTRY>
	<ENTRY> convert to datetime </ENTRY>
	<ENTRY> datetime('1998-02-24'::datetime, '23:07'::time); </ENTRY>
354
  </ROW>
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
       <ROW>
	<ENTRY> date_part(text,datetime) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> specified portion of date field </ENTRY>
	<ENTRY> date_part('dow','now'::datetime) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> date_part(text,timespan) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> specified portion of time field </ENTRY>
	<ENTRY> date_part('hour','4 hrs 3 mins'::timespan) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> date_trunc(text,datetime) </ENTRY>
	<ENTRY> datetime </ENTRY>
	<ENTRY> truncate date at specified units </ENTRY>
	<ENTRY> date_trunc('month','now'::abstime) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> isfinite(abstime) </ENTRY>
	<ENTRY> bool </ENTRY>
	<ENTRY> TRUE if this is a finite time </ENTRY>
	<ENTRY> isfinite('now'::abstime) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> isfinite(datetime) </ENTRY>
	<ENTRY> bool </ENTRY>
	<ENTRY> TRUE if this is a finite time </ENTRY>
	<ENTRY> isfinite('now'::datetime) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> isfinite(timespan) </ENTRY>
	<ENTRY> bool </ENTRY>
	<ENTRY> TRUE if this is a finite time </ENTRY>
	<ENTRY> isfinite('4 hrs'::timespan) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> reltime(timespan) </ENTRY>
	<ENTRY> reltime </ENTRY>
	<ENTRY> convert to reltime </ENTRY>
	<ENTRY> reltime('4 hrs'::timespan) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> timespan(reltime) </ENTRY>
	<ENTRY> timespan </ENTRY>
	<ENTRY> convert to timespan </ENTRY>
	<ENTRY> timespan('4 hours'::reltime) </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
407

408 409 410 411 412 413 414 415 416 417 418 419
   <Para>
    For the
    <Function>date_part</Function> and <Function>date_trunc</Function>
    functions, arguments can be
    `year', `month', `day', `hour', `minute', and `second',
    as well as the more specialized quantities
    `decade', `century', `millenium', `millisecond', and `microsecond'.
    <Function>date_part</Function> allows `dow'
    to return day of week and `epoch' to return seconds since 1970 (for <Type>datetime</Type>)
    or 'epoch' to return total elapsed seconds (for <Type>timespan</Type>).
   </Para>
  </sect1>
420

421 422
  <sect1>
   <title>Geometric Functions</title>
423

424 425 426 427
   <para>
    The geometric types point, box, lseg, line, path, polygon, and
    circle have a large set of native support functions.
   </para>
428

429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
   <Para>
    <TABLE TOCENTRY="1">
     <TITLE>Geometric Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> area(box) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> area of box </ENTRY>
	<ENTRY> area('((0,0),(1,1))'::box) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> area(circle) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> area of circle </ENTRY>
	<ENTRY> area('((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> box(box,box) </ENTRY>
	<ENTRY> box </ENTRY>
	<ENTRY> boxes to intersection box </ENTRY>
	<ENTRY> box('((0,0),(1,1))','((0.5,0.5),(2,2))') </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> center(box) </ENTRY>
	<ENTRY> point </ENTRY>
	<ENTRY> center of object </ENTRY>
	<ENTRY> center('((0,0),(1,2))'::box) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> center(circle) </ENTRY>
	<ENTRY> point </ENTRY>
	<ENTRY> center of object </ENTRY>
	<ENTRY> center('((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> diameter(circle) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> diameter of circle </ENTRY>
	<ENTRY> diameter('((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> height(box) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> vertical size of box </ENTRY>
	<ENTRY> height('((0,0),(1,1))'::box) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> isclosed(path) </ENTRY>
	<ENTRY> bool </ENTRY>
	<ENTRY> TRUE if this is a closed path </ENTRY>
	<ENTRY> isclosed('((0,0),(1,1),(2,0))'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> isopen(path) </ENTRY>
	<ENTRY> bool </ENTRY>
	<ENTRY> TRUE if this is an open path </ENTRY>
	<ENTRY> isopen('[(0,0),(1,1),(2,0)]'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> length(lseg) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> length of line segment </ENTRY>
	<ENTRY> length('((-1,0),(1,0))'::lseg) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> length(path) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> length of path </ENTRY>
	<ENTRY> length('((0,0),(1,1),(2,0))'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> pclose(path) </ENTRY>
	<ENTRY> path </ENTRY>
	<ENTRY> convert path to closed variant </ENTRY>
	<ENTRY> popen('[(0,0),(1,1),(2,0)]'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> point(lseg,lseg) </ENTRY>
	<ENTRY> point </ENTRY>
	<ENTRY> convert to point (intersection) </ENTRY>
	<ENTRY> point('((-1,0),(1,0))'::lseg,'((-2,-2),(2,2))'::lseg) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> points(path) </ENTRY>
	<ENTRY> int4 </ENTRY>
	<ENTRY> number of points in path </ENTRY>
	<ENTRY> points('[(0,0),(1,1),(2,0)]'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> popen(path) </ENTRY>
	<ENTRY> path </ENTRY>
	<ENTRY> convert path to open variant </ENTRY>
	<ENTRY> popen('((0,0),(1,1),(2,0))'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> radius(circle) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> radius of circle </ENTRY>
	<ENTRY> radius('((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> width(box) </ENTRY>
	<ENTRY> float8 </ENTRY>
	<ENTRY> horizontal size of box </ENTRY>
	<ENTRY> width('((0,0),(1,1))'::box) </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
548

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
   <Para>
    <TABLE TOCENTRY="1">
     <TITLE>Geometric Type Conversion Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> box(circle) </ENTRY>
	<ENTRY> box </ENTRY>
	<ENTRY> convert circle to box </ENTRY>
	<ENTRY> box('((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> box(point,point) </ENTRY>
	<ENTRY> box </ENTRY>
	<ENTRY> convert points to box </ENTRY>
	<ENTRY> box('(0,0)'::point,'(1,1)'::point) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> box(polygon) </ENTRY>
	<ENTRY> box </ENTRY>
	<ENTRY> convert polygon to box </ENTRY>
	<ENTRY> box('((0,0),(1,1),(2,0))'::polygon) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> circle(box) </ENTRY>
	<ENTRY> circle </ENTRY>
	<ENTRY> convert to circle </ENTRY>
	<ENTRY> circle('((0,0),(1,1))'::box) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> circle(point,float8) </ENTRY>
	<ENTRY> circle </ENTRY>
	<ENTRY> convert to circle </ENTRY>
	<ENTRY> circle('(0,0)'::point,2.0) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> lseg(box) </ENTRY>
	<ENTRY> lseg </ENTRY>
	<ENTRY> convert diagonal to lseg </ENTRY>
	<ENTRY> lseg('((-1,0),(1,0))'::box) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> lseg(point,point) </ENTRY>
	<ENTRY> lseg </ENTRY>
	<ENTRY> convert to lseg </ENTRY>
	<ENTRY> lseg('(-1,0)'::point,'(1,0)'::point) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> path(polygon) </ENTRY>
	<ENTRY> point </ENTRY>
	<ENTRY> convert to path </ENTRY>
	<ENTRY> path('((0,0),(1,1),(2,0))'::polygon) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> point(circle) </ENTRY>
	<ENTRY> point </ENTRY>
	<ENTRY> convert to point (center) </ENTRY>
	<ENTRY> point('((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> point(lseg,lseg) </ENTRY>
	<ENTRY> point </ENTRY>
	<ENTRY> convert to point (intersection) </ENTRY>
	<ENTRY> point('((-1,0),(1,0))'::lseg,'((-2,-2),(2,2))'::lseg) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> point(polygon) </ENTRY>
	<ENTRY> point </ENTRY>
	<ENTRY> center of polygon </ENTRY>
	<ENTRY> point('((0,0),(1,1),(2,0))'::polygon) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> polygon(box) </ENTRY>
	<ENTRY> polygon </ENTRY>
	<ENTRY> convert to polygon with 12 points </ENTRY>
	<ENTRY> polygon('((0,0),(1,1))'::box) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> polygon(circle) </ENTRY>
	<ENTRY> polygon </ENTRY>
	<ENTRY> convert to polygon with 12 points </ENTRY>
	<ENTRY> polygon('((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> polygon(npts,circle) </ENTRY>
	<ENTRY> polygon </ENTRY>
	<ENTRY> convert to polygon with npts points </ENTRY>
	<ENTRY> polygon(12,'((0,0),2.0)'::circle) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> polygon(path) </ENTRY>
	<ENTRY> polygon </ENTRY>
	<ENTRY> convert to polygon </ENTRY>
	<ENTRY> polygon('((0,0),(1,1),(2,0))'::path) </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
656

657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
   <Para>
    <TABLE TOCENTRY="1">
     <TITLE>Geometric Upgrade Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> isoldpath(path) </ENTRY>
	<ENTRY> path </ENTRY>
	<ENTRY> test path for pre-v6.1 form </ENTRY>
	<ENTRY> isoldpath('(1,3,0,0,1,1,2,0)'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> revertpoly(polygon) </ENTRY>
	<ENTRY> polygon </ENTRY>
	<ENTRY> convert pre-v6.1 polygon </ENTRY>
	<ENTRY> revertpoly('((0,0),(1,1),(2,0))'::polygon) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> upgradepath(path) </ENTRY>
	<ENTRY> path </ENTRY>
	<ENTRY> convert pre-v6.1 path </ENTRY>
	<ENTRY> upgradepath('(1,3,0,0,1,1,2,0)'::path) </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> upgradepoly(polygon) </ENTRY>
	<ENTRY> polygon </ENTRY>
	<ENTRY> convert pre-v6.1 polygon </ENTRY>
	<ENTRY> upgradepoly('(0,1,2,0,1,0)'::polygon) </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
  </sect1>
699

700 701
  <sect1>
   <title id="cidr-funcs">IP V4 Functions</title>
702

703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
   <Para>
    <TABLE TOCENTRY="1">
     <TITLE><ProductName>Postgres</ProductName>IP V4 Functions</TITLE>
     <TGROUP COLS="4">
      <THEAD>
       <ROW>
	<ENTRY>Function</ENTRY>
	<ENTRY>Returns</ENTRY>
	<ENTRY>Description</ENTRY>
	<ENTRY>Example</ENTRY>
       </ROW>
      </THEAD>
      <TBODY>
       <ROW>
	<ENTRY> broadcast(cidr) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> construct broadcast address as text </ENTRY>
	<ENTRY> broadcast('192.168.1.5/24') ==> '192.168.1.255' </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> broadcast(inet) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> construct broadcast address as text </ENTRY>
	<ENTRY> broadcast('192.168.1.5/24') ==> '192.168.1.255' </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> host(inet) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> extract host address as text </ENTRY>
	<ENTRY> host('192.168.1.5/24') ==> '192.168.1.5' </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> masklen(cidr) </ENTRY>
	<ENTRY> int4 </ENTRY>
	<ENTRY> calculate netmask length </ENTRY>
	<ENTRY> masklen('192.168.1.5/24') ==> 24</ENTRY>
       </ROW>
       <ROW>
	<ENTRY> masklen(inet) </ENTRY>
	<ENTRY> int4 </ENTRY>
	<ENTRY> calculate netmask length </ENTRY>
	<ENTRY> masklen('192.168.1.5/24') ==> 24 </ENTRY>
       </ROW>
       <ROW>
	<ENTRY> netmask(inet) </ENTRY>
	<ENTRY> text </ENTRY>
	<ENTRY> construct netmask as text </ENTRY>
	<ENTRY> netmask('192.168.1.5/24') ==> '255.255.255.0' </ENTRY>
       </ROW>
      </TBODY>
     </TGROUP>
    </TABLE>
   </Para>
756

757
  </Sect1>
758

759
 </chapter>
760

761 762 763
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
764
sgml-omittag:nil
765 766 767 768 769 770 771 772 773 774 775 776
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"./reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->