diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 70a0d383c02f252f4c7716798ebfd5e201717be0..0d7b03596cfa0f6c34f1c94a4d09ca0fdb047ac7 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -190,26 +190,38 @@ several possibilities for formats, such as date and time types. Postgres has features at the forefront of ORDBMS development. In addition to SQL3 conformance, substantial portions of SQL92 are also supported. -Although we strive for SQL92 compliance, there are some cases in the standard +Although we strive for SQL92 compliance, there are some aspects of the standard which are ill considered and which should not live through subsequent standards. -Postgres will not make great efforts to conform to these cases. However, these -cases tend to be little-used and obsure, and a typical user is not likely to +Postgres will not make great efforts to conform to these aspects; +however, these +tend to apply in little-used or obsure cases, and a typical user is not likely to run into them. -Although most of the input and output functions corresponding to the +Most of the input and output functions corresponding to the base types (e.g., integers and floating point numbers) do some -error-checking, some are not particularly rigorous about it. More -importantly, few of the operators and functions (e.g., -addition and multiplication) perform any error-checking at all. -Consequently, many of the numeric operators can (for example) +error-checking. +Some of the operators and functions (e.g., +addition and multiplication) do not perform run-time error-checking in the +interests of improving execution speed. +On some systems, for example, the numeric operators for some data types may silently underflow or overflow. -Some of the input and output functions are not invertible. That is, +Note that some of the input and output functions are not invertible. That is, the result of an output function may lose precision when compared to the original input. + + + +The original Postgres v4.2 code received from +Berkeley rounded all double precision floating point results to six digits for +output. Starting with v6.1, floating point numbers are allowed to retain +most of the intrinsic precision of the type (typically 15 digits for doubles, 6 digits +for 4-byte floats). Other types with underlying floating point fields (e.g. geometric +types) carry similar precision. + @@ -245,17 +257,23 @@ floating point numbers. Usual choice for fixed-precision -2147483648 to +2147483647 + + int8 + 8 bytes + Very large range fixed-precision + +/- > 18 decimal places + float4 4 bytes Variable-precision - 7 decimal places + 6 decimal places float8 8 bytes Variable-precision - 14 decimal places + 15 decimal places @@ -266,6 +284,7 @@ floating point numbers. The exact numerics decimal and numeric have fully implemented syntax but currently (Postgres v6.3) support only a small range of precision and/or range values. +The int8 type may not be available on all platforms. @@ -1267,790 +1286,3 @@ Circles are output using the first syntax. - -Operators - - -Postgres provides a large number of built-in operators on system types. -These operators are declared in the system catalog -pg_operator. Every entry in pg_operator includes -the name of the procedure that implements the operator and the -class OIDs of the input and output types. - - -To view all variations of the || string concatenation operator, try - - SELECT oprleft, oprright, oprresult, oprcode - FROM pg_operator WHERE oprname = '||'; - -oprleft|oprright|oprresult|oprcode --------+--------+---------+------- - 25| 25| 25|textcat - 1042| 1042| 1042|textcat - 1043| 1043| 1043|textcat -(3 rows) - - - - - -<ProductName>Postgres</ProductName> Operators -Operators - - - - Operator - Description - Usage - - - - - < - Less than? - 1 < 2 - - - <= - Less than or equal to? - 1 <= 2 - - - <> - Not equal? - 1 <> 2 - - - = - Equal? - 1 = 1 - - - > - Greater than? - 2 > 1 - - - >= - Greater than or equal to? - 2 >= 1 - - - || - Concatenate strings - 'Postgre' || 'SQL' - - - !!= - NOT IN - 3 !!= i - - - ~~ - LIKE - 'scrappy,marc,hermit' ~~ '%scrappy%' - - - !~~ - NOT LIKE - 'bruce' !~~ '%al%' - - - ~ - Match (regex), case sensitive - 'thomas' ~ '*.thomas*.' - - - ~* - Match (regex), case insensitive - 'thomas' ~* '*.Thomas*.' - - - !~ - Does not match (regex), case sensitive - 'thomas' !~ '*.Thomas*.' - - - !~* - Does not match (regex), case insensitive - 'thomas' !~ '*.vadim*.' - - - -
-
- - - -<ProductName>Postgres</ProductName> Numerical Operators -Operators - - - - Operator - Description - Usage - - - - - ! - Factorial - 3 ! - - - !! - Factorial (left operator) - !! 3 - - - % - Modulo - 5 % 4 - - - % - Truncate - % 4.5 - - - * - Multiplication - 2 * 3 - - - + - Addition - 2 + 3 - - - - - Subtraction - 2 - 3 - - - / - Division - 4 / 2 - - - : - Natural Exponentiation - : 3.0 - - - ; - Natural Logarithm - (; 5.0) - - - @ - Absolute value - @ -5.0 - - - ^ - Exponentiation - 2.0 ^ 3.0 - - - |/ - Square root - |/ 25.0 - - - ||/ - Cube root - ||/ 27.0 - - - -
-
- - - -<ProductName>Postgres</ProductName> Geometric Operators -Operators - - - - Operator - Description - Usage - - - - - + - Translation - '((0,0),(1,1))'::box + '(2.0,0)'::point - - - - - Translation - '((0,0),(1,1))'::box - '(2.0,0)'::point - - - * - Scaling/rotation - '((0,0),(1,1))'::box * '(2.0,0)'::point - - - / - Scaling/rotation - '((0,0),(2,2))'::box / '(2.0,0)'::point - - - # - Intersection - '((1,-1),(-1,1))' # '((1,1),(-1,-1))' - - - # - Number of points in polygon - # '((1,0),(0,1),(-1,0))' - - - ## - Point of closest proximity - '(0,0)'::point ## '((2,0),(0,2))'::lseg - - - && - Overlaps? - '((0,0),(1,1))'::box && '((0,0),(2,2))'::box - - - &< - Overlaps to left? - '((0,0),(1,1))'::box &< '((0,0),(2,2))'::box - - - &> - Overlaps to right? - '((0,0),(3,3))'::box &> '((0,0),(2,2))'::box - - - <-> - Distance between - '((0,0),1)'::circle <-> '((5,0),1)'::circle - - - << - Left of? - '((0,0),1)'::circle << '((5,0),1)'::circle - - - <^ - Is below? - '((0,0),1)'::circle <^ '((0,5),1)'::circle - - - >> - Is right of? - '((5,0),1)'::circle >> '((0,0),1)'::circle - - - >^ - Is above? - '((0,5),1)'::circle >^ '((0,0),1)'::circle - - - ?# - Intersects or overlaps - '((-1,0),(1,0))'::lseg ?# '((-2,-2),(2,2))'::box; - - - ?- - Is horizontal? - '(1,0)'::point ?- '(0,0)'::point - - - ?-| - Is perpendicular? - '((0,0),(0,1))'::lseg ?-| '((0,0),(1,0))'::lseg - - - @-@ - Length or circumference - @-@ '((0,0),(1,0))'::path - - - ?| - Is vertical? - '(0,1)'::point ?| '(0,0)'::point - - - ?|| - Is parallel? - '((-1,0),(1,0))'::lseg ?|| '((-1,2),(1,2))'::lseg - - - @ - Contained or on - '(1,1)'::point @ '((0,0),2)'::circle - - - @@ - Center of - @@ '((0,0),10)'::circle - - - ~= - Same as - '((0,0),(1,1))'::polygon ~= '((1,1),(0,0))'::polygon - - - -
-
- - -The time interval data type tinterval is a legacy from the original -date/time types and is not as well supported as the more modern types. There -are several operators for this type. - - -<ProductName>Postgres</ProductName> Time Interval Operators -Operators - - - - Operator - Description - Usage - - - - - #< - Interval less than? - - - - #<= - Interval less than or equal to? - - - - #<> - Interval not equal? - - - - #= - Interval equal? - - - - #> - Interval greater than? - - - - #>= - Interval greater than or equal to? - - - - <#> - Convert to time interval - - - - << - Interval less than? - - - - | - Start of interval - - - - ~= - Same as - - - - <?> - Time inside interval? - - - - -
-
- - - -Users may invoke operators using the operator name, as in: - - -select * from emp where salary < 40000; - - -Alternatively, users may call the functions that implement the -operators directly. In this case, the query above would be expressed -as: - -select * from emp where int4lt(salary, 40000); - - - -psql -has a \dd command to show these operators. -
- - -Functions - - -Many data types have functions available for conversion to other related types. -In addition, there are some type-specific functions. Functions which are also -available through operators are documented as operators only. - - - -Some functions defined for text are also available for char() and varchar(). - - - -For the -date_part and date_trunc -functions, arguments can be -`year', `month', `day', `hour', `minute', and `second', -as well as the more specialized quantities -`decade', `century', `millenium', `millisecond', and `microsecond'. -date_part allows `dow' -to return day of week and `epoch' to return seconds since 1970 (for datetime) -or 'epoch' to return total elapsed seconds (for timespan). - - - - -Mathematical Functions - - - - Function - Returns - Description - Example - - - - - float(int) - float8 - convert integer to floating point - float(2) - - - float4(int) - float4 - convert integer to floating point - float4(2) - - - int - integer(float) - convert floating point to integer - integer(2.0) - - - -
-
- - -Many of the string functions are available for text, varchar(), and char() types. -At the moment, some functions are available only for the text type. - - -String Functions - - - - Function - Returns - Description - Example - - - - - lower(text) - text - convert text to lower case - lower('TOM') - - - lpad(text,int,text) - text - left pad string to specified length - lpad('hi',4,'??') - - - ltrim(text,text) - text - left trim characters from text - ltrim('xxxxtrim','x') - - - position(text,text) - text - extract specified substring - position('high','ig') - - - rpad(text,int,text) - text - right pad string to specified length - rpad('hi',4,'x') - - - rtrim(text,text) - text - right trim characters from text - rtrim('trimxxxx','x') - - - substr(text,int[,int]) - text - extract specified substring - substr('hi there',3,5) - - - upper(text) - text - convert text to upper case - upper('tom') - - - -
-
- - - -Date/Time Functions - - - - Function - Returns - Description - Example - - - - - isfinite(abstime) - bool - TRUE if this is a finite time - isfinite('now'::abstime) - - - datetime(abstime) - datetime - convert to datetime - datetime('now'::abstime) - - - datetime(date) - datetime - convert to datetime - datetime('today'::date) - - - datetime(date,time) - datetime - convert to datetime - datetime('1998-02-24'::datetime, '23:07'::time); - - - age(datetime,datetime) - timespan - span preserving months and years - age('now','1957-06-13'::datetime) - - - date_part(text,datetime) - float8 - specified portion of date field - date_part('dow','now'::datetime) - - - date_trunc(text,datetime) - datetime - truncate date at specified units - date_trunc('month','now'::abstime) - - - isfinite(datetime) - bool - TRUE if this is a finite time - isfinite('now'::datetime) - - - abstime(datetime) - abstime - convert to abstime - abstime('now'::datetime) - - - timespan(reltime) - timespan - convert to timespan - timespan('4 hours'::reltime) - - - datetime(date,time) - datetime - convert to datetime - datetime('1998-02-25'::date,'06:41'::time) - - - date_part(text,timespan) - float8 - specified portion of time field - date_part('hour','4 hrs 3 mins'::timespan) - - - isfinite(timespan) - bool - TRUE if this is a finite time - isfinite('4 hrs'::timespan) - - - reltime(timespan) - reltime - convert to reltime - reltime('4 hrs'::timespan) - - - -
-
- - - -Geometric Functions - - - - Function - Returns - Description - Example - - - - - box(point,point) - box - convert points to box - box('(0,0)'::point,'(1,1)'::point) - - - area(box) - float8 - area of box - area('((0,0),(1,1))'::box) - - - isopen(path) - bool - TRUE if this is an open path - isopen('[(0,0),(1,1),(2,0)]'::path) - - - isclosed(path) - bool - TRUE if this is a closed path - isclosed('((0,0),(1,1),(2,0))'::path) - - - circle(point,float8) - circle - convert to circle - circle('(0,0)'::point,2.0) - - - polygon(npts,circle) - polygon - convert to polygon with npts points - polygon(12,'((0,0),2.0)'::circle) - - - center(circle) - float8 - center of object - center('((0,0),2.0)'::circle) - - - radius(circle) - float8 - radius of circle - radius('((0,0),2.0)'::circle) - - - diameter(circle) - float8 - diameter of circle - diameter('((0,0),2.0)'::circle) - - - area(circle) - float8 - area of circle - area('((0,0),2.0)'::circle) - - - -
-
- - -SQL92 defines functions with specific syntax. Some of these -are implemented using other Postgres functions. - - - - -<Acronym>SQL92</Acronym> Text Functions - - - - Function - Returns - Description - Example - - - - - position(text in text) - int4 - extract specified substring - position('o' in 'Tom') - - - substring(text [from int] [for int]) - text - extract specified substring - substring('Tom' from 2 for 2) - - - trim([leading|trailing|both] [text] from text) - text - trim characters from text - trim(both 'x' from 'xTomx') - - - -
-
- diff --git a/doc/src/sgml/docguide.sgml b/doc/src/sgml/docguide.sgml index 03b6356134ad6110b661f5fda6065b77f566fadf..3e571f33ad8aaaac8e81df71ec143e42168c8b54 100644 --- a/doc/src/sgml/docguide.sgml +++ b/doc/src/sgml/docguide.sgml @@ -239,7 +239,7 @@ right, and I can verify the document with "nsgmls -s docguide.sgml". Building Documentation -GNU make is used to build documentation from the DocBook sources. +GNU make is used to build documentation from the DocBook sources. There are a few environment definitions which may need to be set or modified for your installation. The Makefile looks for doc/../src/Makefile diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml new file mode 100644 index 0000000000000000000000000000000000000000..91d86a9fa774750b33a9e6b6d9983fdef5129170 --- /dev/null +++ b/doc/src/sgml/func.sgml @@ -0,0 +1,616 @@ + +Functions + + + +Describes the built-in functions available in Postgres. + + + + +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. + + + +Mathematical Functions + + + +Mathematical Functions + + + + Function + Returns + Description + Example + + + + + dexp(float8) + float8 + raise e to the specified exponent + dexp(2.0) + + + dpow(float8,float8) + float8 + raise a number to the specified exponent + dpow(2.0, 16.0) + + + float(int) + float8 + convert integer to floating point + float(2) + + + float4(int) + float4 + convert integer to floating point + float4(2) + + + integer(float) + int + convert floating point to integer + integer(2.0) + + + +
+
+ + +String Functions + + +SQL92 defines string functions with specific syntax. Some of these +are implemented using other Postgres functions. + + + + +<Acronym>SQL92</Acronym> Text Functions + + + + Function + Returns + Description + Example + + + + + position(text in text) + int4 + location of specified substring + position('o' in 'Tom') + + + substring(text [from int] [for int]) + text + extract specified substring + substring('Tom' from 2 for 2) + + + trim([leading|trailing|both] [text] from text) + text + trim characters from text + trim(both 'x' from 'xTomx') + + + +
+
+ + +Many string functions are available for text, varchar(), and char() types. +Some are used internally to implement the SQL92 string functions listed above. + + + + +String Functions + + + + Function + Returns + Description + Example + + + + + char(text) + char + convert text to char type + char('text string') + + + char(varchar) + char + convert varchar to char type + char(varchar 'varchar string') + + + lower(text) + text + convert text to lower case + lower('TOM') + + + lpad(text,int,text) + text + left pad string to specified length + lpad('hi',4,'??') + + + ltrim(text,text) + text + left trim characters from text + ltrim('xxxxtrim','x') + + + position(text,text) + text + extract specified substring + position('high','ig') + + + rpad(text,int,text) + text + right pad string to specified length + rpad('hi',4,'x') + + + rtrim(text,text) + text + right trim characters from text + rtrim('trimxxxx','x') + + + substr(text,int[,int]) + text + extract specified substring + substr('hi there',3,5) + + + text(char) + text + convert char to text type + text('char string') + + + text(varchar) + text + convert varchar to text type + text(varchar 'varchar string') + + + varchar(char) + varchar + convert char to varchar type + varchar('char string') + + + varchar(text) + varchar + convert text to varchar type + varchar('text string') + + + upper(text) + text + convert text to upper case + upper('tom') + + + +
+
+ + +Most functions explicitly defined for text will work for char() and varchar() arguments. + + + +Date/Time Functions + + +The date/time functions provide a powerful set of tools for manipulating various date/time types. + + + + +Date/Time Functions + + + + Function + Returns + Description + Example + + + + + abstime(datetime) + abstime + convert to abstime + abstime('now'::datetime) + + + age(datetime,datetime) + timespan + span preserving months and years + age('now','1957-06-13'::datetime) + + + datetime(abstime) + datetime + convert to datetime + datetime('now'::abstime) + + + datetime(date) + datetime + convert to datetime + datetime('today'::date) + + + datetime(date,time) + datetime + convert to datetime + datetime('1998-02-24'::datetime, '23:07'::time); + + + date_part(text,datetime) + float8 + specified portion of date field + date_part('dow','now'::datetime) + + + date_part(text,timespan) + float8 + specified portion of time field + date_part('hour','4 hrs 3 mins'::timespan) + + + date_trunc(text,datetime) + datetime + truncate date at specified units + date_trunc('month','now'::abstime) + + + isfinite(abstime) + bool + TRUE if this is a finite time + isfinite('now'::abstime) + + + isfinite(datetime) + bool + TRUE if this is a finite time + isfinite('now'::datetime) + + + isfinite(timespan) + bool + TRUE if this is a finite time + isfinite('4 hrs'::timespan) + + + reltime(timespan) + reltime + convert to reltime + reltime('4 hrs'::timespan) + + + timespan(reltime) + timespan + convert to timespan + timespan('4 hours'::reltime) + + + +
+
+ + +For the +date_part and date_trunc +functions, arguments can be +`year', `month', `day', `hour', `minute', and `second', +as well as the more specialized quantities +`decade', `century', `millenium', `millisecond', and `microsecond'. +date_part allows `dow' +to return day of week and `epoch' to return seconds since 1970 (for datetime) +or 'epoch' to return total elapsed seconds (for timespan). + + + +Geometric Functions + + +The geometric types point, box, lseg, line, path, polygon, and circle have a large set of native +support functions. + + + + +Geometric Functions + + + + Function + Returns + Description + Example + + + + + area(box) + float8 + area of box + area('((0,0),(1,1))'::box) + + + area(circle) + float8 + area of circle + area('((0,0),2.0)'::circle) + + + box(box,box) + box + boxes to intersection box + box('((0,0),(1,1))','((0.5,0.5),(2,2))') + + + center(box) + point + center of object + center('((0,0),(1,2))'::box) + + + center(circle) + point + center of object + center('((0,0),2.0)'::circle) + + + diameter(circle) + float8 + diameter of circle + diameter('((0,0),2.0)'::circle) + + + height(box) + float8 + vertical size of box + height('((0,0),(1,1))'::box) + + + isclosed(path) + bool + TRUE if this is a closed path + isclosed('((0,0),(1,1),(2,0))'::path) + + + isopen(path) + bool + TRUE if this is an open path + isopen('[(0,0),(1,1),(2,0)]'::path) + + + length(lseg) + float8 + length of line segment + length('((-1,0),(1,0))'::lseg) + + + length(path) + float8 + length of path + length('((0,0),(1,1),(2,0))'::path) + + + pclose(path) + path + convert path to closed variant + popen('[(0,0),(1,1),(2,0)]'::path) + + + point(lseg,lseg) + point + convert to point (intersection) + point('((-1,0),(1,0))'::lseg,'((-2,-2),(2,2))'::lseg) + + + points(path) + int4 + number of points in path + points('[(0,0),(1,1),(2,0)]'::path) + + + popen(path) + path + convert path to open variant + popen('((0,0),(1,1),(2,0))'::path) + + + radius(circle) + float8 + radius of circle + radius('((0,0),2.0)'::circle) + + + width(box) + float8 + horizontal size of box + width('((0,0),(1,1))'::box) + + + +
+
+ + + +Geometric Type Conversion Functions + + + + Function + Returns + Description + Example + + + + + box(circle) + box + convert circle to box + box('((0,0),2.0)'::circle) + + + box(point,point) + box + convert points to box + box('(0,0)'::point,'(1,1)'::point) + + + box(polygon) + box + convert polygon to box + box('((0,0),(1,1),(2,0))'::polygon) + + + circle(box) + circle + convert to circle + circle('((0,0),(1,1))'::box) + + + circle(point,float8) + circle + convert to circle + circle('(0,0)'::point,2.0) + + + lseg(box) + lseg + convert diagonal to lseg + lseg('((-1,0),(1,0))'::box) + + + lseg(point,point) + lseg + convert to lseg + lseg('(-1,0)'::point,'(1,0)'::point) + + + path(polygon) + point + convert to path + path('((0,0),(1,1),(2,0))'::polygon) + + + point(circle) + point + convert to point (center) + point('((0,0),2.0)'::circle) + + + point(lseg,lseg) + point + convert to point (intersection) + point('((-1,0),(1,0))'::lseg,'((-2,-2),(2,2))'::lseg) + + + point(polygon) + point + center of polygon + point('((0,0),(1,1),(2,0))'::polygon) + + + polygon(box) + polygon + convert to polygon with 12 points + polygon('((0,0),(1,1))'::box) + + + polygon(circle) + polygon + convert to polygon with 12 points + polygon('((0,0),2.0)'::circle) + + + polygon(npts,circle) + polygon + convert to polygon with npts points + polygon(12,'((0,0),2.0)'::circle) + + + polygon(path) + polygon + convert to polygon + polygon('((0,0),(1,1),(2,0))'::path) + + + +
+
+ + + +Geometric Upgrade Functions + + + + Function + Returns + Description + Example + + + + + isoldpath(path) + path + test path for pre-v6.1 form + isoldpath('(1,3,0,0,1,1,2,0)'::path) + + + revertpoly(polygon) + polygon + convert pre-v6.1 polygon + revertpoly('((0,0),(1,1),(2,0))'::polygon) + + + upgradepath(path) + path + convert pre-v6.1 path + upgradepath('(1,3,0,0,1,1,2,0)'::path) + + + upgradepoly(polygon) + polygon + convert pre-v6.1 polygon + upgradepoly('(0,1,2,0,1,0)'::polygon) + + + +
+
+ +
+ diff --git a/doc/src/sgml/oper.sgml b/doc/src/sgml/oper.sgml new file mode 100644 index 0000000000000000000000000000000000000000..5ec76cf452ee4c7a87f3ea34fe472b9d19ba77fb --- /dev/null +++ b/doc/src/sgml/oper.sgml @@ -0,0 +1,458 @@ + +Operators + + + +Describes the built-in operators available in Postgres. + + + + +Postgres provides a large number of built-in operators on system types. +These operators are declared in the system catalog +pg_operator. Every entry in pg_operator includes +the name of the procedure that implements the operator and the +class OIDs of the input and output types. + + +To view all variations of the || string concatenation operator, try + + SELECT oprleft, oprright, oprresult, oprcode + FROM pg_operator WHERE oprname = '||'; + +oprleft|oprright|oprresult|oprcode +-------+--------+---------+------- + 25| 25| 25|textcat + 1042| 1042| 1042|textcat + 1043| 1043| 1043|textcat +(3 rows) + + + + +General Operators + + +The operators listed here are defined for a number of native data types, ranging +from numeric types to data/time types. + + + +<ProductName>Postgres</ProductName> Operators +Operators + + + + Operator + Description + Usage + + + + + < + Less than? + 1 < 2 + + + <= + Less than or equal to? + 1 <= 2 + + + <> + Not equal? + 1 <> 2 + + + = + Equal? + 1 = 1 + + + > + Greater than? + 2 > 1 + + + >= + Greater than or equal to? + 2 >= 1 + + + || + Concatenate strings + 'Postgre' || 'SQL' + + + !!= + NOT IN + 3 !!= i + + + ~~ + LIKE + 'scrappy,marc,hermit' ~~ '%scrappy%' + + + !~~ + NOT LIKE + 'bruce' !~~ '%al%' + + + ~ + Match (regex), case sensitive + 'thomas' ~ '*.thomas*.' + + + ~* + Match (regex), case insensitive + 'thomas' ~* '*.Thomas*.' + + + !~ + Does not match (regex), case sensitive + 'thomas' !~ '*.Thomas*.' + + + !~* + Does not match (regex), case insensitive + 'thomas' !~ '*.vadim*.' + + + +
+
+ + +Numerical Operators + + + +<ProductName>Postgres</ProductName> Numerical Operators +Operators + + + + Operator + Description + Usage + + + + + ! + Factorial + 3 ! + + + !! + Factorial (left operator) + !! 3 + + + % + Modulo + 5 % 4 + + + % + Truncate + % 4.5 + + + * + Multiplication + 2 * 3 + + + + + Addition + 2 + 3 + + + - + Subtraction + 2 - 3 + + + / + Division + 4 / 2 + + + : + Natural Exponentiation + : 3.0 + + + ; + Natural Logarithm + (; 5.0) + + + @ + Absolute value + @ -5.0 + + + ^ + Exponentiation + 2.0 ^ 3.0 + + + |/ + Square root + |/ 25.0 + + + ||/ + Cube root + ||/ 27.0 + + + +
+
+ + +Geometric Operators + + + +<ProductName>Postgres</ProductName> Geometric Operators +Operators + + + + Operator + Description + Usage + + + + + + + Translation + '((0,0),(1,1))'::box + '(2.0,0)'::point + + + - + Translation + '((0,0),(1,1))'::box - '(2.0,0)'::point + + + * + Scaling/rotation + '((0,0),(1,1))'::box * '(2.0,0)'::point + + + / + Scaling/rotation + '((0,0),(2,2))'::box / '(2.0,0)'::point + + + # + Intersection + '((1,-1),(-1,1))' # '((1,1),(-1,-1))' + + + # + Number of points in polygon + # '((1,0),(0,1),(-1,0))' + + + ## + Point of closest proximity + '(0,0)'::point ## '((2,0),(0,2))'::lseg + + + && + Overlaps? + '((0,0),(1,1))'::box && '((0,0),(2,2))'::box + + + &< + Overlaps to left? + '((0,0),(1,1))'::box &< '((0,0),(2,2))'::box + + + &> + Overlaps to right? + '((0,0),(3,3))'::box &> '((0,0),(2,2))'::box + + + <-> + Distance between + '((0,0),1)'::circle <-> '((5,0),1)'::circle + + + << + Left of? + '((0,0),1)'::circle << '((5,0),1)'::circle + + + <^ + Is below? + '((0,0),1)'::circle <^ '((0,5),1)'::circle + + + >> + Is right of? + '((5,0),1)'::circle >> '((0,0),1)'::circle + + + >^ + Is above? + '((0,5),1)'::circle >^ '((0,0),1)'::circle + + + ?# + Intersects or overlaps + '((-1,0),(1,0))'::lseg ?# '((-2,-2),(2,2))'::box; + + + ?- + Is horizontal? + '(1,0)'::point ?- '(0,0)'::point + + + ?-| + Is perpendicular? + '((0,0),(0,1))'::lseg ?-| '((0,0),(1,0))'::lseg + + + @-@ + Length or circumference + @-@ '((0,0),(1,0))'::path + + + ?| + Is vertical? + '(0,1)'::point ?| '(0,0)'::point + + + ?|| + Is parallel? + '((-1,0),(1,0))'::lseg ?|| '((-1,2),(1,2))'::lseg + + + @ + Contained or on + '(1,1)'::point @ '((0,0),2)'::circle + + + @@ + Center of + @@ '((0,0),10)'::circle + + + ~= + Same as + '((0,0),(1,1))'::polygon ~= '((1,1),(0,0))'::polygon + + + +
+
+ + +Time Interval Operators + + +The time interval data type tinterval is a legacy from the original +date/time types and is not as well supported as the more modern types. There +are several operators for this type. + + +<ProductName>Postgres</ProductName> Time Interval Operators +Operators + + + + Operator + Description + Usage + + + + + #< + Interval less than? + + + + #<= + Interval less than or equal to? + + + + #<> + Interval not equal? + + + + #= + Interval equal? + + + + #> + Interval greater than? + + + + #>= + Interval greater than or equal to? + + + + <#> + Convert to time interval + + + + << + Interval less than? + + + + | + Start of interval + + + + ~= + Same as + + + + <?> + Time inside interval? + + + + +
+
+ + + +Users may invoke operators using the operator name, as in: + + +select * from emp where salary < 40000; + + +Alternatively, users may call the functions that implement the +operators directly. In this case, the query above would be expressed +as: + +select * from emp where int4lt(salary, 40000); + + + +psql +has a command (\dd) to show these operators. +
+ diff --git a/doc/src/sgml/postgres.sgml b/doc/src/sgml/postgres.sgml index 67adad9e21dd528c464d6adcb932d7e40c821e5d..820b39cfddf857ca32343b34453b7aa7a96ee103 100644 --- a/doc/src/sgml/postgres.sgml +++ b/doc/src/sgml/postgres.sgml @@ -18,6 +18,9 @@ + + + @@ -162,6 +165,9 @@ Information for users. &environ; &manage; &datatype; +&oper; +&func; +&typeconv; &array; &inherit; &query-ug; diff --git a/doc/src/sgml/release.sgml b/doc/src/sgml/release.sgml index 93048018a056c909d4e48df309876403f04a2659..11aa90af7314e05a7479169a23a20890f6d1fa70 100644 --- a/doc/src/sgml/release.sgml +++ b/doc/src/sgml/release.sgml @@ -7,74 +7,804 @@ Should include the migration notes from migration/.
- - -The release notes have not yet been integrated into the new documentation. +The release notes have not yet been fully integrated into the new documentation. Check for plain text files in the top of the distribution directory tree and in the migration/ directory for current information. -Release 6.3 +Release 6.4 TBD - - -Release 6.2.1 +Release 6.3.2 + + + +This is a bugfix release for 6.3.x. +Refer to the release notes for v6.3 for a more complete summary of new features. + + +Summary: + + + + +Repairs automatic configuration support for some platforms, including Linux, +from breakage inadvertently introduced in v6.3.1. + + + +Correctly handles function calls at the left side of BETWEEN and LIKE clauses. + + - +A dump/restore is NOT required for those running 6.3 or 6.3.1. A +'make distclean', 'make', and 'make install' is all that is required. +This last step should be performed while the postmaster is not running. +You should re-link any custom applications that use Postgres libraries. + + +For upgrades from pre-v6.3 installations, +refer to the installation and migration instructions for v6.3. + + +Detailed Change List + + + +Changes +------- +Configure detection improvements for tcl/tk(Brook Milligan, Alvin) +Manual page improvements(Bruce) +BETWEEN and LIKE fix(Thomas) +fix for psql \connect used by pg_dump(Oliver Elphick) +New odbc driver +pgaccess, version 0.86 +qsort removed, now uses libc version, cleanups(Jeroen) +fix for buffer over-runs detected(Maurice Gittens) +fix for buffer overrun in libpgtcl(Randy Kunkee) +fix for UNION with DISTINCT or ORDER BY(Bruce) +gettimeofday configure check(Doug Winterburn) +Fix "indexes not used" bug(Vadim) +docs additions(Thomas) +Fix for backend memory leak(Bruce) +libreadline cleanup(Erwan MAS) +Remove DISTDIR(Bruce) +Makefile dependency cleanup(Jeroen van Vianen) +ASSERT fixes(Bruce) + + + + +Release 6.3.1 + + + +Summary: + + + + +Additional support for multi-byte character sets. + + + +Repair byte ordering for mixed-endian clients and servers. + + + +Minor updates to allowed SQL syntax. + + + +Improvements to the configuration autodetection for installation. + + + + + + -v6.2.1 was a bug-fix and usability release on v6.2. Needs only a few notes. - - +A dump/restore is NOT required for those running 6.3. A +'make distclean', 'make', and 'make install' is all that is required. +This last step should be performed while the postmaster is not running. +You should re-link any custom applications that use Postgres libraries. + + +For upgrades from pre-v6.3 installations, +refer to the installation and migration instructions for v6.3. + + +Detailed Change List + + + +Changes +------- +ecpg cleanup/fixes, now version 1.1(Michael Meskes) +pg_user cleanup(Bruce) +large object fix for pg_dump and tclsh (alvin) +LIKE fix for multiple adjacent underscores +fix for redefining builtin functions(Thomas) +ultrix4 cleanup +upgrade to pg_access 0.83 +updated CLUSTER manual page +multi-byte character set support, see doc/README.mb(Tatsuo) +configure --with-pgport fix +pg_ident fix +big-endian fix for backend communications(Kataoka) +SUBSTR() and substring() fix(Jan) +several jdbc fixes(Peter) +libpgtcl improvements, see libptcl/README(Randy Kunkee) +Fix for "Datasize = 0" error(Vadim) +Prevent \do from wrapping(Bruce) +Remove duplicate Russian character set entries +Sunos4 cleanup +Allow optional TABLE keyword in LOCK and SELECT INTO(Thomas) +CREATE SEQUENCE options to allow a negative integer(Thomas) +Add "PASSWORD" as an allowed column identifier(Thomas) +Add checks for UNION target fields(Bruce) +Fix Alpha port(Dwayne Bailey) +Fix for text arrays containing quotes(Doug Gibson) +Solaris compile fix(Albert Chin-A-Young) +Better identify tcl and tk libs and includes(Bruce) + + + + +Release 6.3 + + + +There are many new features and improvements in this release. +Here is a brief, incomplete summary: + + + + +Many new SQL features, including +full SQL92 subselect capability +(everything is here but target-list subselects). + + + +Support for client-side environment variables to specify time zone and date style. + + + +Socket interface for client/server connection. This is the default now +so you may need to start postmaster with the +-i flag. + + + +Better password authorization mechanisms. Default table permissions have changed. + + + +Old-style time travel has been removed. Performance has been improved. + + + + + +Bruce Momjian wrote the following notes to introduce the new release. + + + +There are some general 6.3 issues that I want to mention. These are +only the big items that can not be described in one sentence. A review +of the detailed changes list is still needed. + + +First, we now have subselects. Now that we have them, I would like to +mention that without subselects, SQL is a very limited language. +Subselects are a major feature, and you should review your code for +places where subselects provide a better solution for your queries. I +think you will find that there are more uses for subselects than you may +think. Vadim has put us on the big SQL map with subselects, and fully +functional ones too. The only thing you can't do with subselects is to +use them in the target list. + + +Second, 6.3 uses unix domain sockets rather than TCP/IP by default. To +enable connections from other machines, you have to use the new +postmaster -i option, and of course edit pg_hba.conf. Also, for this +reason, the format of pg_hba.conf has changed. + + +Third, char() fields will now allow faster access than varchar() or +text. Specifically, the text and varchar() have a penalty for access to +any columns after the first column of this type. char() used to also +have this access penalty, but it no longer does. This may suggest that +you redesign some of your tables, especially if you have short character +columns that you have defined as varchar() or text. This and other +changes make 6.3 even faster than earlier releases. + + +We now have passwords definable independent of any Unix file. There are +new SQL USER commands. See the pg_hba.conf manual page for more +information. There is a new table, pg_shadow, which is used to store +user information and user passwords, and it by default only SELECT-able +by the postgres super-user. pg_user is now a view of pg_shadow, and is +SELECT-able by PUBLIC. You should keep using pg_user in your +application without changes. + + +User-created tables now no longer have SELECT permission to PUBLIC by +default. This was done because the ANSI standard requires it. You can +of course GRANT any permissions you want after the table is created. +System tables continue to be SELECT-able by PUBLIC. + + +We also have real deadlock detection code. No more sixty-second +timeouts. And the new locking code implements a FIFO better, so there +should be less resource starvation during heavy use. + + +Many complaints have been made about inadequate documenation in previous +releases. Thomas has put much effort into many new manuals for this +release. Check out the doc/ directory. + + +For performance reasons, time travel is gone, but can be implemented +using triggers (see pgsql/contrib/spi/README). Please check out the new +\d command for types, operators, etc. Also, views have their own +permissions now, not based on the underlying tables, so permissions on +them have to be set separately. Check /pgsql/interfaces for some new +ways to talk to Postgres. + + +This is the first release that really required an explanation for +existing users. In many ways, this was necessary because the new +release removes many limitations, and the work-arounds people were using +are no longer needed. + + + +Migration to v6.3 + + +A dump/restore using pg_dump +or pg_dumpall +is required for those wishing to migrate data from any +previous release of Postgres. + + + +Detailed Change List + + + +Bug Fixes +--------- +Fix binary cursors broken by MOVE implementation(Vadim) +Fix for tcl library crash(Jan) +Fix for array handling, from Gerhard Hintermayer +Fix acl error, and remove duplicate pqtrace(Bruce) +Fix psql \e for empty file(Bruce) +Fix for textcat on varchar() fields(Bruce) +Fix for DBT Sendproc (Zeugswetter Andres) +Fix vacuum analyze syntax problem(Bruce) +Fix for international identifiers(Tatsuo) +Fix aggregates on inherited tables(Bruce) +Fix substr() for out-of-bounds data +Fix for select 1=1 or 2=2, select 1=1 and 2=2, and select sum(2+2)(Bruce) +Fix notty output to show status result. -q option still turns it off(Bruce) +Fix for count(*), aggs with views and multiple tables and sum(3)(Bruce) +Fix cluster(Bruce) +Fix for PQtrace start/stop several times(Bruce) +Fix a variety of locking problems like newer lock waiters getting + lock before older waiters, and having readlock people not share + locks if a writer is waiting for a lock, and waiting writers not + getting priority over waiting readers(Bruce) +Fix crashes in psql when executing queries from external files(James) +Fix problem with multiple order by columns, with the first one having + NULL values(Jeroen) +Use correct hash table support functions for float8 and int4(Thomas) +Re-enable JOIN= option in CREATE OPERATOR statement (Thomas) +Change precedence for boolean operators to match expected behavior(Thomas) +Generate elog(ERROR) on over-large integer(Bruce) +Allow multiple-argument functions in constraint clauses(Thomas) +Check boolean input literals for 'true','false','yes','no','1','0' + and throw elog(ERROR) if unrecognized(Thomas) +Major large objects fix +Fix for GROUP BY showing duplicates(Vadim) +Fix for index scans in MergeJion(Vadim) + +Enhancements +------------ +Subselects with EXISTS, IN, ALL, ANY keywords (Vadim, Bruce, Thomas) +New User Manual(Thomas, others) +Speedup by inlining some frequently-called functions +Real deadlock detection, no more timeouts(Bruce) +Add SQL92 "constants" CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, + CURRENT_USER(Thomas) +Modify constraint syntax to be SQL92-compliant(Thomas) +Implement SQL92 PRIMARY KEY and UNIQUE clauses using indices(Thomas) +Recognize SQL92 syntax for FOREIGN KEY. Throw elog notice(Thomas) +Allow NOT NULL UNIQUE constraint clause (each allowed separately before)(Thomas) +Allow Postgres-style casting ("::") of non-constants(Thomas) +Add support for SQL3 TRUE and FALSE boolean constants(Thomas) +Support SQL92 syntax for IS TRUE/IS FALSE/IS NOT TRUE/IS NOT FALSE(Thomas) +Allow shorter strings for boolean literals (e.g. "t", "tr", "tru")(Thomas) +Allow SQL92 delimited identifiers(Thomas) +Implement SQL92 binary and hexadecimal string decoding (b'10' and x'1F')(Thomas) +Support SQL92 syntax for type coercion of literal strings + (e.g. "DATETIME 'now'")(Thomas) +Add conversions for int2, int4, and OID types to and from text(Thomas) +Use shared lock when building indices(Vadim) +Free memory allocated for an user query inside transaction block after + this query is done, was turned off in <= 6.2.1(Vadim) +New SQL statement CREATE PROCEDURAL LANGUAGE(Jan) +New Postgres Procedural Language (PL) backend interface(Jan) +Rename pg_dump -H option to -h(Bruce) +Add Java support for passwords, European dates(Peter) +Use indices for LIKE and ~, !~ operations(Bruce) +Add hash functions for datetime and timespan(Thomas) +Time Travel removed(Vadim, Bruce) +Add paging for \d and \z, and fix \i(Bruce) +Add Unix domain socket support to backend and to frontend library(Goran) +Implement CREATE DATABASE/WITH LOCATION and initlocation utility(Thomas) +Allow more SQL92 and/or Postgres reserved words as column identifiers(Thomas) +Augment support for SQL92 SET TIME ZONE...(Thomas) +SET/SHOW/RESET TIME ZONE uses TZ backend environment variable(Thomas) +Implement SET keyword = DEFAULT and SET TIME ZONE DEFAULT(Thomas) +Enable SET TIME ZONE using TZ environment variable(Thomas) +Add PGDATESTYLE environment variable to frontend and backend initialization(Thomas) +Add PGTZ, PGCOSTHEAP, PGCOSTINDEX, PGRPLANS, PGGEQO + frontend library initialization environment variables(Thomas) +Regression tests time zone automatically set with "setenv PGTZ PST8PDT"(Thomas) +Add pg_description table for info on tables, columns, operators, types, and + aggregates(Bruce) +Increase 16 char limit on system table/index names to 32 characters(Bruce) +Rename system indices(Bruce) +Add 'GERMAN' option to SET DATESTYLE(Thomas) +Define an "ISO-style" timespan output format with "hh:mm:ss" fields(Thomas) +Allow fractional values for delta times (e.g. '2.5 days')(Thomas) +Validate numeric input more carefully for delta times(Thomas) +Implement day of year as possible input to date_part()(Thomas) +Define timespan_finite() and text_timespan() functions(Thomas) +Remove archive stuff(Bruce) +Allow for a pg_password authentication database that is separate from + the system password file(Todd) +Dump ACLs, GRANT, REVOKE permissions(Matt) +Define text, varchar, and bpchar string length functions(Thomas) +Fix Query handling for inheritance, and cost computations(Bruce) +Implement CREATE TABLE/AS SELECT (alternative to SELECT/INTO)(Thomas) +Allow NOT, IS NULL, IS NOT NULL in constraints(Thomas) +Implement UNIONs for SELECT(Bruce) +Add UNION, GROUP, DISTINCT to INSERT(Bruce) +varchar() stores only necessary bytes on disk(Bruce) +Fix for BLOBs(Peter) +Mega-Patch for JDBC...see README_6.3 for list of changes(Peter) +Remove unused "option" from PQconnectdb() +New LOCK command and lock manual page describing deadlocks(Bruce) +Add new psql \da, \dd, \df, \do, \dS, and \dT commands(Bruce) +Enhance psql \z to show sequences(Bruce) +Show NOT NULL and DEFAULT in psql \d table(Bruce) +New psql .psqlrc file startup(Andrew) +Modify sample startup script in contrib/linux to show syslog(Thomas) +New types for IP and MAC addresses in contrib/ip_and_mac(TomH) +Unix system time conversions with date/time types in contrib/unixdate(Thomas) +Update of contrib stuff(Massimo) +Add Unix socket support to DBD::Pg(Goran) +New python interface (PyGreSQL 2.0)(D'Arcy) +New frontend/backend protocol has a version number, network byte order(Phil) +Security features in pg_hba.conf enhanced and documented, many cleanups(Phil) +CHAR() now faster access than VARCHAR() or TEXT +ecpg embedded SQL preprocessor +Reduce system column overhead(Vadmin) +Remove pg_time table(Vadim) +Add pg_type attribute to identify types that need length (bpchar, varchar) +Add report of offending line when COPY command fails +Allow VIEW permissions to be set separately from the underlying tables. + For security, use GRANT/REVOKE on views as appropriate(Jan) +Tables now have no default GRANT SELECT TO PUBLIC. You must + explicitly grant such permissions. +Clean up tutorial examples(Darren) + +Source Tree Changes +------------------- +Add new html development tools, and flow chart in /tools/backend +Fix for SCO compiles +Stratus computer port Robert Gillies +Added support for shlib for BSD44_derived & i386_solaris +Make configure more automated(Brook) +Add script to check regression test results +Break parser functions into smaller files, group together(Bruce) +Rename heap_create to heap_create_and_catalog, rename heap_creatr + to heap_create()(Bruce) +Sparc/Linux patch for locking(TomS) +Remove PORTNAME and reorganize port-specific stuff(Marc) +Add optimizer README file(Bruce) +Remove some recursion in optimizer and clean up some code there(Bruce) +Fix for NetBSD locking(Henry) +Fix for libptcl make(Tatsuo) +AIX patch(Darren) +Change IS TRUE, IS FALSE, ... to expressions using "=" rather than + function calls to istrue() or isfalse() to allow optimization(Thomas) +Various fixes NetBSD/Sparc related(TomH) +Alpha linux locking(Travis,Ryan) +Change elog(WARN) to elog(ERROR)(Bruce) +FAQ for FreeBSD(Marc) +Bring in the PostODBC source tree as part of our standard distribution(Marc) +A minor patch for HP/UX 10 vs 9(Stan) +New pg_attribute.atttypmod for type-specific info like varchar length(Bruce) +Unixware patches(Billy) +New i386 'lock' for spin lock asm(Billy) +Support for multiplexed backends is removed +Start an OpenBSD port +Start an AUX port +Start a Cygnus port +Add string functions to regression suite(Thomas) +Expand a few function names formerly truncated to 16 characters(Thomas) +Remove un-needed malloc() calls and replace with palloc()(Bruce) + -Release 6.2 +Release 6.2.1 + - - - -This should include information based on Bruce's release summary. - - - + +v6.2.1 is a bug-fix and usability release on v6.2. + +Summary: + + + + +Allow strings to span lines, per SQL92. + + + +Include example trigger function for inserting user names on table updates. + + + + +This is a minor bug-fix release on v6.2. +For upgrades from pre-v6.2 systems, a full dump/reload is required. +Refer to the v6.2 release notes for instructions. + + +Migration from v6.2 to v6.2.1 + + +This is a minor bug-fix release. A dump/reload is not required from v6.2, +but is required from any release prior to v6.2. + + +In upgrading from v6.2, if you choose to dump/reload you will find that +avg(money) is now calculated correctly. All other bug fixes take effect +upon updating the executables. + + +Another way to avoid dump/reload is to use the following SQL command +from psql to update the existing system table: + + + update pg_aggregate set aggfinalfn = 'cash_div_flt8' + where aggname = 'avg' and aggbasetype = 790; + + + +This will need to be done to every existing database, including template1. + + +Detailed Change List + + + +Changes in this release +----------------------- +Allow TIME and TYPE column names(Thomas) +Allow larger range of true/false as boolean values(Thomas) +Support output of "now" and "current"(Thomas) +Handle DEFAULT with INSERT of NULL properly(Vadim) +Fix for relation reference counts problem in buffer manager(Vadim) +Allow strings to span lines, like ANSI(Thomas) +Fix for backward cursor with ORDER BY(Vadim) +Fix avg(cash) computation(Thomas) +Fix for specifying a column twice in ORDER/GROUP BY(Vadim) +Documented new libpq function to return affected rows, PQcmdTuples(Bruce) +Trigger function for inserting user names for INSERT/UPDATE(Brook Milligan) + -Release 6.1 +Release 6.2 + - - - -This should include information based on Bruce's release summary. - - - + +A dump/restore is required for those wishing to migrate data from +previous releases of Postgres. + + +Migration from v6.1 to v6.2 + + +This migration requires a complete dump of the 6.1 database and a +restore of the database in 6.2. + + +Note that the pg_dump and pg_dumpall utility from 6.2 should be used +to dump the 6.1 database. + + +Migration from v1.x to v6.2 + + +Those migrating from earlier 1.* releases should first upgrade to 1.09 +because the COPY output format was improved from the 1.02 release. + + +Detailed Change List + + + +Bug Fixes +--------- +Fix problems with pg_dump for inheritance, sequences, archive tables(Bruce) +Fix compile errors on overflow due to shifts, unsigned, and bad prototypes + from Solaris(Diab Jerius) +Fix bugs in geometric line arithmetic (bad intersection calculations)(Thomas) +Check for geometric intersections at endpoints to avoid rounding ugliness(Thomas) +Catch non-functional delete attempts(Vadim) +Change time function names to be more consistent(Michael Reifenberg) +Check for zero divides(Michael Reifenberg) +Fix very old bug which made tuples changed/inserted by a commnd + visible to the command itself (so we had multiple update of + updated tuples, etc)(Vadim) +Fix for SELECT null, 'fail' FROM pg_am (Patrick) +SELECT NULL as EMPTY_FIELD now allowed(Patrick) +Remove un-needed signal stuff from contrib/pginterface +Fix OR (where x <> 1 or x isnull didn't return tuples with x NULL) (Vadim) +Fix time_cmp function (Vadim) +Fix handling of functions with non-attribute first argument in + WHERE clauses (Vadim) +Fix GROUP BY when order of entries is different from order + in target list (Vadim) +Fix pg_dump for aggregates without sfunc1 (Vadim) + +Enhancements +------------ +Default genetic optimizer GEQO parameter is now 8(Bruce) +Allow use parameters in target list having aggregates in functions(Vadim) +Added JDBC driver as an interface(Adrian & Peter) +pg_password utility +Return number of tuples inserted/affected by INSERT/UPDATE/DELETE etc.(Vadim) +Triggers implemented with CREATE TRIGGER (SQL3)(Vadim) +SPI (Server Programming Interface) allows execution of queries inside + C-functions (Vadim) +NOT NULL implemented (SQL92)(Robson Paniago de Miranda) +Include reserved words for string handling, outer joins, and unions(Thomas) +Implement extended comments ("/* ... */") using exclusive states(Thomas) +Add "//" single-line comments(Bruce) +Remove some restrictions on characters in operator names(Thomas) +DEFAULT and CONSTRAINT for tables implemented (SQL92)(Vadim & Thomas) +Add text concatenation operator and function (SQL92)(Thomas) +Support WITH TIME ZONE syntax (SQL92)(Thomas) +Support INTERVAL unit TO unit syntax (SQL92)(Thomas) +Define types DOUBLE PRECISION, INTERVAL, CHARACTER, + and CHARACTER VARYING (SQL92)(Thomas) +Define type FLOAT(p) and rudimentary DECIMAL(p,s), NUMERIC(p,s) (SQL92)(Thomas) +Define EXTRACT(), POSITION(), SUBSTRING(), and TRIM() (SQL92)(Thomas) +Define CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP (SQL92)(Thomas) +Add syntax and warnings for UNION, HAVING, INNER and OUTER JOIN (SQL92)(Thomas) +Add more reserved words, mostly for SQL92 compliance(Thomas) +Allow hh:mm:ss time entry for timespan/reltime types(Thomas) +Add center() routines for lseg, path, polygon(Thomas) +Add distance() routines for circle-polygon, polygon-polygon(Thomas) +Check explicitly for points and polygons contained within polygons + using an axis-crossing algorithm(Thomas) +Add routine to convert circle-box(Thomas) +Merge conflicting operators for different geometric data types(Thomas) +Replace distance operator "<===>" with "<->"(Thomas) +Replace "above" operator "!^" with ">^" and "below" operator "!|" with "<^"(Thomas) +Add routines for text trimming on both ends, substring, and string position(Thomas) +Added conversion routines circle(box) and poly(circle)(Thomas) +Allow internal sorts to be stored in memory rather than in files(Bruce & Vadim) +Allow functions and operators on internally-identical types to succeed(Bruce) +Speed up backend startup after profiling analysis(Bruce) +Inline frequently called functions for performance(Bruce) +Reduce open() calls(Bruce) +psql: Add PAGER for \h and \?,\C fix +Fix for psql pager when no tty(Bruce) +New entab utility(Bruce) +General trigger functions for referential integrity (Vadim) +General trigger functions for time travel (Vadim) +General trigger functions for AUTOINCREMENT/IDENTITY feature (Vadim) +MOVE implementation (Vadim) + +Source Tree Changes +------------------- +HPUX 10 patches (Vladimir Turin) +Added SCO support, (Daniel Harris) +mkLinux patches (Tatsuo Ishii) +Change geometric box terminology from "length" to "width"(Thomas) +Deprecate temporary unstored slope fields in geometric code(Thomas) +Remove restart instructions from INSTALL(Bruce) +Look in /usr/ucb first for install(Bruce) +Fix c++ copy example code(Thomas) +Add -o to psql manual page(Bruce) +Prevent relname unallocated string length from being copied into database(Bruce) +Cleanup for NAMEDATALEN use(Bruce) +Fix pg_proc names over 15 chars in output(Bruce) +Add strNcpy() function(Bruce) +remove some (void) casts that are unnecessary(Bruce) +new interfaces directory(Marc) +Replace fopen() calls with calls to fd.c functions(Bruce) +Make functions static where possible(Bruce) +enclose unused functions in #ifdef NOT_USED(Bruce) +Remove call to difftime() in timestamp support to fix SunOS(Bruce & Thomas) +Changes for Digital Unix +Portability fix for pg_dumpall(Bruce) +Rename pg_attribute.attnvals to attdisbursion(Bruce) +"intro/unix" manual page now "pgintro"(Bruce) +"built-in" manual page now "pgbuiltin"(Bruce) +"drop" manual page now "drop_table"(Bruce) +Add "create_trigger", "drop_trigger" manual pages(Thomas) +Add constraints regression test(Vadim & Thomas) +Add comments syntax regression test(Thomas) +Add PGINDENT and support program(Bruce) +Massive commit to run PGINDENT on all *.c and *.h files(Bruce) +Files moved to /src/tools directory(Bruce) +SPI and Trigger programming guides (Vadim & D'Arcy) + + + + +Release 6.1.1 + + + + +Migration from v6.1 to v6.1.1 + + +This is a minor bug-fix release. A dump/reload is not required from v6.1, +but is required from any release prior to v6.1. +Refer to the release notes for v6.1 for more details. + + +Detailed Change List + + + +Changes in this release +----------------------- +fix for SET with options (Thomas) +allow pg_dump/pg_dumpall to preserve ownership of all tables/objects(Bruce) +new psql \connect option allows changing usernames without chaning databases +fix for initdb --debug option(Yoshihiko Ichikawa)) +lextest cleanup(Bruce) +hash fixes(Vadim) +fix date/time month boundary arithmetic(Thomas) +fix timezone daylight handling for some ports(Thomas, Bruce, Tatsuo) +timestamp overhauled to use standard functions(Thomas) +other code cleanup in date/time routines(Thomas) +psql's \d now case-insensitive(Bruce) +psql's backslash commands can now have trailing semicolon(Bruce) +fix memory leak in psql when using \g(Bruce) +major fix for endian handling of communication to server(Thomas, Tatsuo) +Fix for Solaris assembler and include files(Yoshihiko Ichikawa) +allow underscores in usernames(Bruce) +pg_dumpall now returns proper status, portability fix(Bruce) + + + + + +Release 6.1 + The regression tests have been adapted and extensively modified for the - v6.1 release of PostgreSQL. + v6.1 release of Postgres. Three new data types (datetime, timespan, and circle) have been added to - the native set of PostgreSQL types. Points, boxes, paths, and polygons + the native set of Postgres types. Points, boxes, paths, and polygons have had their output formats made consistant across the data types. The polygon output in misc.out has only been spot-checked for correctness relative to the original regression output. - PostgreSQL v6.1 introduces a new, alternate optimizer which uses genetic + Postgres v6.1 introduces a new, alternate optimizer which uses genetic algorithms. These algorithms introduce a random behavior in the ordering of query results when the query contains multiple qualifiers or multiple tables (giving the optimizer a choice on order of evaluation). Several @@ -105,23 +835,926 @@ This should include information based on Bruce's release summary. test machine (Linux/gcc/i686). + +Migration to v6.1 + + +This migration requires a complete dump of the 6.0 database and a +restore of the database in 6.1. + + +Those migrating from earlier 1.* releases should first upgrade to 1.09 +because the COPY output format was improved from the 1.02 release. + + +Detailed Change List + + + +Bug Fixes +--------- +packet length checking in library routines +lock manager priority patch +check for under/over flow of float8(Bruce) +multi-table join fix(Vadim) +SIGPIPE crash fix(Darren) +large object fixes(Sven) +allow btree indexes to handle NULLs(Vadim) +timezone fixes(D'Arcy) +select SUM(x) can return NULL on no rows(Thomas) +internal optimizer, executor bug fixes(Vadim) +fix problem where inner loop in < or <= has no rows(Vadim) +prevent re-commuting join index clauses(Vadim) +fix join clauses for multiple tables(Vadim) +fix hash, hashjoin for arrays(Vadim) +fix btree for abstime type(Vadim) +large object fixes(Raymond) +fix buffer leak in hash indices (Vadim) +fix rtree for use in inner scan (Vadim) +fix gist for use in inner scan, cleanups (Vadim, Andrea) +avoid unnecessary local buffers allocation (Vadim, Massimo) +fix local buffers leak in transaction aborts (Vadim) +fix file manager memmory leaks, cleanups (Vadim, Massimo) +fix storage manager memmory leaks (Vadim) +fix btree duplicates handling (Vadim) +fix deleted tuples re-incarnation caused by vacuum (Vadim) +fix SELECT varchar()/char() INTO TABLE made zero-length fields(Bruce) +many psql, pg_dump, and libpq memory leaks fixed using Purify (Igor) + +Enhancements +------------ +attribute optimization statistics(Bruce) +much faster new btree bulk load code(Paul) +BTREE UNIQUE added to bulk load code(Vadim) +new lock debug code(Massimo) +massive changes to libpg++(Leo) +new GEQO optimizer speeds table multi-table optimization(Martin) +new WARN message for non-unique insert into unique key(Marc) +update x=-3, no spaces, now valid(Bruce) +remove case-sensitive identifier handling(Bruce,Thomas,Dan) +debug backend now pretty-prints tree(Darren) +new Oracle character functions(Edmund) +new plaintext password functions(Dan) +no such class or insufficient privilege changed to distinct messages(Dan) +new ANSI timestamp function(Dan) +new ANSI Time and Date types (Thomas) +move large chunks of data in backend(Martin) +multi-column btree indexes(Vadim) +new SET var TO value command(Martin) +update transaction status on reads(Dan) +new locale settings for character types(Oleg) +new SEQUENCE serial number generator(Vadim) +GROUP BY function now possible(Vadim) +re-organize regression test(Thomas,Marc) +new optimizer operation weights(Vadim) +new psql \z grant/permit option(Marc) +new MONEY data type(D'Arcy,Thomas) +tcp socket communication speed improved(Vadim) +new VACUUM option for attribute statistics, and for certain columns (Vadim) +many geometric type improvements(Thomas,Keith) +additional regression tests(Thomas) +new datestyle variable(Thomas,Vadim,Martin) +more comparison operators for sorting types(Thomas) +new conversion functions(Thomas) +new more compact btree format(Vadim) +allow pg_dumpall to preserve database ownership(Bruce) +new SET GEQO=# and R_PLANS variable(Vadim) +old (!GEQO) optimizer can use right-sided plans (Vadim) +typechecking improvement in SQL parser(Bruce) +new SET, SHOW, RESET commands(Thomas,Vadim) +new \connect database USER option +new destroydb -i option (Igor) +new \dt and \di psql commands (Darren) +SELECT "\n" now escapes newline (A. Duursma) +new geometry conversion functions from old format (Thomas) + +Source tree changes +------------------- +new configuration script(Marc) +readline configuration option added(Marc) +OS-specific configuration options removed(Marc) +new OS-specific template files(Marc) +no more need to edit Makefile.global(Marc) +re-arrange include files(Marc) +nextstep patches (Gregor Hoffleit) +removed WIN32-specific code(Bruce) +removed postmaster -e option, now only postgres -e option (Bruce) +merge duplicate library code in front/backends(Martin) +now works with eBones, international Kerberos(Jun) +more shared library support +c++ include file cleanup(Bruce) +warn about buggy flex(Bruce) +DG-UX, Ultrix, Irix, AIX portability fixes + + + + +Release v6.0 + + + +A dump/restore is required for those wishing to migrate data from +previous releases of Postgres. + + +Migration from v1.09 to v6.0 + + +This migration requires a complete dump of the 1.09 database and a +restore of the database in 6.0. + + +Migration from pre-v1.09 to v6.0 + + +Those migrating from earlier 1.* releases should first upgrade to 1.09 +because the COPY output format was improved from the 1.02 release. + + +Detailed Change List + + + +Bug Fixes +--------- +ALTER TABLE bug - running postgress process needs to re-read table definition +Allow vacuum to be run on one table or entire database(Bruce) +Array fixes +Fix array over-runs of memory writes(Kurt) +Fix elusive btree range/non-range bug(Dan) +Fix for hash indexes on some types like time and date +Fix for pg_log size explosion +Fix permissions on lo_export()(Bruce) +Fix unitialized reads of memory(Kurt) +Fixed ALTER TABLE ... char(3) bug(Bruce) +Fixed a few small memory leaks +Fixed EXPLAIN handling of options and changed full_path option name +Fixed output of group acl permissions +Memory leaks (hunt and destroy with tools like Purify(Kurt) +Minor improvements to rules system +NOTIFY fixes +New asserts for run-checking +Overhauled parser/analyze code to properly report errors and increase speed +Pg_dump -d now handles NULL's properly(Bruce) +Prevent SELECT NULL from crashing server (Bruce) +Properly report errors when INSERT ... SELECT columns did not match +Properly report errors when insert column names were not correct +Psql \g filename now works(Bruce) +Psql fixed problem with multiple statements on one line with multiple outputs +Removed duplicate system oid's +SELECT * INTO TABLE . GROUP/ORDER BY gives unlink error if table exists(Bruce) +Several fixes for queries that crashed the backend +Starting quote in insert string errors(Bruce) +Submitting an empty query now returns empty status, not just " " query(Bruce) + +Enhancements +------------ +Add EXPLAIN manual page(Bruce) +Add UNIQUE index capability(Dan) +Add hostname/user level access control rather than just hostname and user +Add synonym of != for <>(Bruce) +Allow "select oid,* from table" +Allow BY,ORDER BY to specify columns by number, or by non-alias table.column(Bruce) +Allow COPY from the frontend(Bryan) +Allow GROUP BY to use alias column name(Bruce) +Allow actual compression, not just reuse on the same page(Vadim) +Allow installation-configuration option to auto-add all local users(Bryan) +Allow libpq to distinguish between text value '' and null(Bruce) +Allow non-postgres users with createdb privs to destroydb's +Allow restriction on who can create C functions(Bryan) +Allow restriction on who can do backend COPY(Bryan) +Can shrink tables, pg_time and pg_log(Vadim & Erich) +Change debug level 2 to print queries only, changed debug heading layout(Bruce) +Change default decimal constant representation from float4 to float8(Bruce) +European date format now set when postmaster is started +Execute lowercase function names if not found with exact case +Fixes for aggregate/GROUP processing, allow 'select sum(func(x),sum(x+y) from z' +Gist now included in the distrubution(Marc) +Idend authentication of local users(Bryan) +Implement BETWEEN qualifier(Bruce) +Implement IN qualifier(Bruce) +Libpq has PQgetisnull()(Bruce) +Libpq++ improvements +New options to initdb(Bryan) +Pg_dump allow dump of oid's(Bruce) +Pg_dump create indexes after tables are loaded for speed(Bruce) +Pg_dumpall dumps all databases, and the user table +Pginterface additions for NULL values(Bruce) +Prevent postmaster from being run as root +Psql \h and \? is now readable(Bruce) +Psql allow backslashed, semicolons anywhere on the line(Bruce) +Psql changed command prompt for lines in query or in quotes(Bruce) +Psql char(3) now displays as (bp)char in \d output(Bruce) +Psql return code now more accurate(Bryan?) +Psql updated help syntax(Bruce) +Re-visit and fix vacuum(Vadim) +Reduce size of regression diffs, remove timezone name difference(Bruce) +Remove compile-time parameters to enable binary distributions(Bryan) +Reverse meaning of HBA masks(Bryan) +Secure Authentication of local users(Bryan) +Speed up vacuum(Vadim) +Vacuum now had VERBOSE option(Bruce) + +Source tree changes +------------------- +All functions now have prototypes that are compared against the calls +Allow asserts to be disabled easly from Makefile.global(Bruce) +Change oid constants used in code to #define names +Decoupled sparc and solaris defines(Kurt) +Gcc -Wall compiles cleanly with warnings only from unfixable constructs +Major include file reorganization/reduction(Marc) +Make now stops on compile failure(Bryan) +Makefile restructuring(Bryan, Marc) +Merge bsdi_2_1 to bsdi(Bruce) +Monitor program removed +Name change from Postgres95 to PostgreSQL +New config.h file(Marc, Bryan) +PG_VERSION now set to 6.0 and used by postmaster +Portability additions, including Ultrix, DG/UX, AIX, and Solaris +Reduced the number of #define's, centeralized #define's +Remove duplicate OIDS in system tables(Dan) +Remove duplicate system catalog info or report mismatches(Dan) +Removed many os-specific #define's +Restructured object file generation/location(Bryan, Marc) +Restructured port-specific file locations(Bryan, Marc) +Unused/uninialized variables corrected + + + + +Release v1.09 + + + +Sorry, we stopped keeping track of changes from 1.02 to 1.09. Some of +the changes listed in 6.0 were actually included in the 1.02.1 to 1.09 +releases. + + + +Release v1.02 + + + +Migration from v1.02 to v1.02.1 + + +Here is a new migration file for 1.02.1. It includes the 'copy' change +and a script to convert old ascii files. + + + +The following notes are for the benefit of users who want to migrate +databases from postgres95 1.01 and 1.02 to postgres95 1.02.1. + + +If you are starting afresh with postgres95 1.02.1 and do not need +to migrate old databases, you do not need to read any further. + + + +In order to upgrade older postgres95 version 1.01 or 1.02 databases to +version 1.02.1, the following steps are required: + + + + +Start up a new 1.02.1 postmaster + + + +Add the new built-in functions and operators of 1.02.1 to 1.01 or 1.02 + databases. This is done by running the new 1.02.1 server against + your own 1.01 or 1.02 database and applying the queries attached at + the end of thie file. This can be done easily through psql. If your + 1.01 or 1.02 database is named "testdb" and you have cut the commands + from the end of this file and saved them in addfunc.sql: + + % psql testdb -f addfunc.sql + + +Those upgrading 1.02 databases will get a warning when executing the +last two statements in the file because they are already present in 1.02. This is +not a cause for concern. + + + +Dump/Reload Procedure + + +If you are trying to reload a pg_dump or text-mode 'copy tablename to +stdout' generated with a previous version, you will need to run the +attached sed script on the ASCII file before loading it into the +database. The old format used '.' as end-of-data, while '\.' is now the +end-of-data marker. Also, empty strings are now loaded in as '' rather +than NULL. See the copy manual page for full details. + + + sed 's/^\.$/\\./g' <in_file >out_file + + + +If you are loading an older binary copy or non-stdout copy, there is no +end-of-data character, and hence no conversion necessary. + + +-- following lines added by agc to reflect the case-insensitive +-- regexp searching for varchar (in 1.02), and bpchar (in 1.02.1) +create operator ~* (leftarg = bpchar, rightarg = text, procedure = texticregexeq); +create operator !~* (leftarg = bpchar, rightarg = text, procedure = texticregexne); +create operator ~* (leftarg = varchar, rightarg = text, procedure = texticregexeq); +create operator !~* (leftarg = varchar, rightarg = text, procedure = texticregexne); + + + + +Detailed Change List + + + +Source code maintenance and development + * worldwide team of volunteers + * the source tree now in CVS at ftp.ki.net + +Enhancements + * psql (and underlying libpq library) now has many more options for + formatting output, including HTML + * pg_dump now output the schema and/or the data, with many fixes to + enhance completeness. + * psql used in place of monitor in administration shell scripts. + monitor to be depreciated in next release. + * date/time functions enhanced + * NULL insert/update/comparison fixed/enhanced + * TCL/TK lib and shell fixed to work with both tck7.4/tk4.0 and tcl7.5/tk4.1 + +Bug Fixes (almost too numerous to mention) + * indexes + * storage management + * check for NULL pointer before dereferencing + * Makefile fixes + +New Ports + * added SolarisX86 port + * added BSDI 2.1 port + * added DGUX port + + + + + +Release v1.01 + + + +Migration from v1.0 to v1.01 + + +The following notes are for the benefit of users who want to migrate +databases from postgres95 1.0 to postgres95 1.01. + + +If you are starting afresh with postgres95 1.01 and do not need +to migrate old databases, you do not need to read any further. + + +In order to postgres95 version 1.01 with databases created with +postgres95 version 1.0, the following steps are required: + + + + +Set the definition of NAMEDATALEN in src/Makefile.global to 16 + and OIDNAMELEN to 20. + + + +Decide whether you want to use Host based authentication. + + + + +If you do, you must create a file name "pg_hba" in your top-level data + directory (typically the value of your $PGDATA). src/libpq/pg_hba + shows an example syntax. + + + +If you do not want host-based authentication, you can comment out + the line + + HBA = 1 + + in src/Makefile.global + + + Note that host-based authentication is turned on by default, and if + you do not take steps A or B above, the out-of-the-box 1.01 will + not allow you to connect to 1.0 databases. + + + + +Compile and install 1.01, but DO NOT do the initdb step. + + + +Before doing anything else, terminate your 1.0 postmaster, and + backup your existing $PGDATA directory. + + + +Set your PGDATA environment variable to your 1.0 databases, but set up + path up so that 1.01 binaries are being used. + + + +Modify the file $PGDATA/PG_VERSION from 5.0 to 5.1 + + + +Start up a new 1.01 postmaster + + + +Add the new built-in functions and operators of 1.01 to 1.0 + databases. This is done by running the new 1.01 server against + your own 1.0 database and applying the queries attached and saving + in the file 1.0_to_1.01.sql. This can be done easily through psql. + If your 1.0 database is name "testdb": + + + % psql testdb -f 1.0_to_1.01.sql + + +and then execute the following commands (cut and paste from here): + + +-- add builtin functions that are new to 1.01 + +create function int4eqoid (int4, oid) returns bool as 'foo' +language 'internal'; +create function oideqint4 (oid, int4) returns bool as 'foo' +language 'internal'; +create function char2icregexeq (char2, text) returns bool as 'foo' +language 'internal'; +create function char2icregexne (char2, text) returns bool as 'foo' +language 'internal'; +create function char4icregexeq (char4, text) returns bool as 'foo' +language 'internal'; +create function char4icregexne (char4, text) returns bool as 'foo' +language 'internal'; +create function char8icregexeq (char8, text) returns bool as 'foo' +language 'internal'; +create function char8icregexne (char8, text) returns bool as 'foo' +language 'internal'; +create function char16icregexeq (char16, text) returns bool as 'foo' +language 'internal'; +create function char16icregexne (char16, text) returns bool as 'foo' +language 'internal'; +create function texticregexeq (text, text) returns bool as 'foo' +language 'internal'; +create function texticregexne (text, text) returns bool as 'foo' +language 'internal'; + +-- add builtin functions that are new to 1.01 + +create operator = (leftarg = int4, rightarg = oid, procedure = int4eqoid); +create operator = (leftarg = oid, rightarg = int4, procedure = oideqint4); +create operator ~* (leftarg = char2, rightarg = text, procedure = char2icregexeq); +create operator !~* (leftarg = char2, rightarg = text, procedure = char2icregexne); +create operator ~* (leftarg = char4, rightarg = text, procedure = char4icregexeq); +create operator !~* (leftarg = char4, rightarg = text, procedure = char4icregexne); +create operator ~* (leftarg = char8, rightarg = text, procedure = char8icregexeq); +create operator !~* (leftarg = char8, rightarg = text, procedure = char8icregexne); +create operator ~* (leftarg = char16, rightarg = text, procedure = char16icregexeq); +create operator !~* (leftarg = char16, rightarg = text, procedure = char16icregexne); +create operator ~* (leftarg = text, rightarg = text, procedure = texticregexeq); +create operator !~* (leftarg = text, rightarg = text, procedure = texticregexne); + + + + + +Detailed Change List + + + +Incompatibilities: + * 1.01 is backwards compatible with 1.0 database provided the user + follow the steps outlined in the MIGRATION_from_1.0_to_1.01 file. + If those steps are not taken, 1.01 is not compatible with 1.0 database. + +Enhancements: + * added PQdisplayTuples() to libpq and changed monitor and psql to use it + * added NeXT port (requires SysVIPC implementation) + * added CAST .. AS ... syntax + * added ASC and DESC keywords + * added 'internal' as a possible language for CREATE FUNCTION + internal functions are C functions which have been statically linked + into the postgres backend. + * a new type "name" has been added for system identifiers (table names, + attribute names, etc.) This replaces the old char16 type. The + of name is set by the NAMEDATALEN #define in src/Makefile.global + * a readable reference manual that describes the query language. + * added host-based access control. A configuration file ($PGDATA/pg_hba) + is used to hold the configuration data. If host-based access control + is not desired, comment out HBA=1 in src/Makefile.global. + * changed regex handling to be uniform use of Henry Spencer's regex code + regardless of platform. The regex code is included in the distribution + * added functions and operators for case-insensitive regular expressions. + The operators are ~* and !~*. + * pg_dump uses COPY instead of SELECT loop for better performance + +Bug fixes: + * fixed an optimizer bug that was causing core dumps when + functions calls were used in comparisons in the WHERE clause + * changed all uses of getuid to geteuid so that effective uids are used + * psql now returns non-zero status on errors when using -c + * applied public patches 1-14 + + + +Release v1.0 + + + +Detailed Change List + + + +Copyright change: + * The copyright of Postgres 1.0 has been loosened to be freely modifiable + and modifiable for any purpose. Please read the COPYRIGHT file. + Thanks to Professor Michael Stonebraker for making this possible. + +Incompatibilities: + * date formats have to be MM-DD-YYYY (or DD-MM-YYYY if you're using + EUROPEAN STYLE). This follows SQL-92 specs. + * "delimiters" is now a keyword + +Enhancements: + * sql LIKE syntax has been added + * copy command now takes an optional USING DELIMITER specification. + delimiters can be any single-character string. + * IRIX 5.3 port has been added. + Thanks to Paul Walmsley and others. + * updated pg_dump to work with new libpq + * \d has been added psql + Thanks to Keith Parks + * regexp performance for architectures that use POSIX regex has been + improved due to caching of precompiled patterns. + Thanks to Alistair Crooks + * a new version of libpq++ + Thanks to William Wanders + +Bug fixes: + * arbitrary userids can be specified in the createuser script + * \c to connect to other databases in psql now works. + * bad pg_proc entry for float4inc() is fixed + * users with usecreatedb field set can now create databases without + having to be usesuper + * remove access control entries when the entry no longer has any + permissions + * fixed non-portable datetimes implementation + * added kerberos flags to the src/backend/Makefile + * libpq now works with kerberos + * typographic errors in the user manual have been corrected. + * btrees with multiple index never worked, now we tell you they don't + work when you try to use them + + + +<productname>Postgres95</productname> Beta 0.03 + + + +Detailed Change List + + + +Incompatible changes: + * BETA-0.3 IS INCOMPATIBLE WITH DATABASES CREATED WITH PREVIOUS VERSIONS + (due to system catalog changes and indexing structure changes). + * double-quote (") is deprecated as a quoting character for string literals; + you need to convert them to single quotes ('). + * name of aggregates (eg. int4sum) are renamed in accordance with the + SQL standard (eg. sum). + * CHANGE ACL syntax is replaced by GRANT/REVOKE syntax. + * float literals (eg. 3.14) are now of type float4 (instead of float8 in + previous releases); you might have to do typecasting if you depend on it + being of type float8. If you neglect to do the typecasting and you assign + a float literal to a field of type float8, you may get incorrect values + stored! + * LIBPQ has been totally revamped so that frontend applications + can connect to multiple backends + * the usesysid field in pg_user has been changed from int2 to int4 to + allow wider range of Unix user ids. + * the netbsd/freebsd/bsd o/s ports have been consolidated into a + single BSD44_derived port. (thanks to Alistair Crooks) + +SQL standard-compliance (the following details changes that makes postgres95 +more compliant to the SQL-92 standard): + * the following SQL types are now built-in: smallint, int(eger), float, real, + char(N), varchar(N), date and time. + + The following are aliases to existing postgres types: + smallint -> int2 + integer, int -> int4 + float, real -> float4 + char(N) and varchar(N) are implemented as truncated text types. In + addition, char(N) does blank-padding. + * single-quote (') is used for quoting string literals; '' (in addition to + \') is supported as means of inserting a single quote in a string + * SQL standard aggregate names (MAX, MIN, AVG, SUM, COUNT) are used + (Also, aggregates can now be overloaded, i.e. you can define your + own MAX aggregate to take in a user-defined type.) + * CHANGE ACL removed. GRANT/REVOKE syntax added. + - Privileges can be given to a group using the "GROUP" keyword. + For example: + GRANT SELECT ON foobar TO GROUP my_group; + The keyword 'PUBLIC' is also supported to mean all users. + + Privileges can only be granted or revoked to one user or group + at a time. + + "WITH GRANT OPTION" is not supported. Only class owners can change + access control + - The default access control is to to grant users readonly access. + You must explicitly grant insert/update access to users. To change + this, modify the line in + src/backend/utils/acl.h + that defines ACL_WORLD_DEFAULT + +Bug fixes: + * the bug where aggregates of empty tables were not run has been fixed. Now, + aggregates run on empty tables will return the initial conditions of the + aggregates. Thus, COUNT of an empty table will now properly return 0. + MAX/MIN of an empty table will return a tuple of value NULL. + * allow the use of \; inside the monitor + * the LISTEN/NOTIFY asynchronous notification mechanism now work + * NOTIFY in rule action bodies now work + * hash indices work, and access methods in general should perform better. + creation of large btree indices should be much faster. (thanks to Paul + Aoki) + +Other changes and enhancements: + * addition of an EXPLAIN statement used for explaining the query execution + plan (eg. "EXPLAIN SELECT * FROM EMP" prints out the execution plan for + the query). + * WARN and NOTICE messages no longer have timestamps on them. To turn on + timestamps of error messages, uncomment the line in + src/backend/utils/elog.h: + /* define ELOG_TIMESTAMPS */ + * On an access control violation, the message + "Either no such class or insufficient privilege" + will be given. This is the same message that is returned when + a class is not found. This dissuades non-privileged users from + guessing the existence of privileged classes. + * some additional system catalog changes have been made that are not + visible to the user. + +libpgtcl changes: + * The -oid option has been added to the "pg_result" tcl command. + pg_result -oid returns oid of the last tuple inserted. If the + last command was not an INSERT, then pg_result -oid returns "". + * the large object interface is available as pg_lo* tcl commands: + pg_lo_open, pg_lo_close, pg_lo_creat, etc. + +Portability enhancements and New Ports: + * flex/lex problems have been cleared up. Now, you should be able to use + flex instead of lex on any platforms. We no longer make assumptions of + what lexer you use based on the platform you use. + * The Linux-ELF port is now supported. Various configuration have been + tested: The following configuration is known to work: + kernel 1.2.10, gcc 2.6.3, libc 4.7.2, flex 2.5.2, bison 1.24 + with everything in ELF format, + +New utilities: + * ipcclean added to the distribution + ipcclean usually does not need to be run, but if your backend crashes + and leaves shared memory segments hanging around, ipcclean will + clean them up for you. + +New documentation: + * the user manual has been revised and libpq documentation added. + + + + +<productname>Postgres95</productname> Beta 0.02 + + + +Detailed Change List + + + +Incompatible changes: + * The SQL statement for creating a database is 'CREATE DATABASE' instead + of 'CREATEDB'. Similarly, dropping a database is 'DROP DATABASE' instead + of 'DESTROYDB'. However, the names of the executables 'createdb' and + 'destroydb' remain the same. + +New tools: + * pgperl - a Perl (4.036) interface to Postgres95 + * pg_dump - a utility for dumping out a postgres database into a + script file containing query commands. The script files are in a ASCII + format and can be used to reconstruct the database, even on other + machines and other architectures. (Also good for converting + a Postgres 4.2 database to Postgres95 database.) + +The following ports have been incorporated into postgres95-beta-0.02: + * the NetBSD port by Alistair Crooks + * the AIX port by Mike Tung + * the Windows NT port by Jon Forrest (more stuff but not done yet) + * the Linux ELF port by Brian Gallew + +The following bugs have been fixed in postgres95-beta-0.02: + * new lines not escaped in COPY OUT and problem with COPY OUT when first + attribute is a '.' + * cannot type return to use the default user id in createuser + * SELECT DISTINCT on big tables crashes + * Linux installation problems + * monitor doesn't allow use of 'localhost' as PGHOST + * psql core dumps when doing \c or \l + * the "pgtclsh" target missing from src/bin/pgtclsh/Makefile + * libpgtcl has a hard-wired default port number + * SELECT DISTINCT INTO TABLE hangs + * CREATE TYPE doesn't accept 'variable' as the internallength + * wrong result using more than 1 aggregate in a SELECT + + + + +<productname>Postgres95</productname> Beta 0.01 + + + +Initial release. + + Timing Results -These timing results are from running the regression test with the command +These timing results are from running the regression test with the commands +% cd src/test/regress +% make all % time make runtest Timing under Linux 2.0.27 seems to have a roughly 5% variation from run - to run, presumably due to the timing vagaries of multitasking systems. + to run, presumably due to the scheduling vagaries of multitasking systems. + + +v6.4beta + + +The times for this release are not directly comparable to those for previous releases +since some additional regression tests have been included. +In general, however, v6.4 should be slightly faster than the previous release (thanks, Bruce!). + + + + Time System + 02:35 Dual Pentium Pro 180, 96MB, UW-SCSI, Linux 2.0.30, gcc 2.7.2.1 -O2 -m486 + v6.3 + +The times for this release are not directly comparable to those for previous releases +since some additional regression tests have been included and some obsolete tests involving +time travel have been removed. +In general, however, v6.3 is substantially faster than previous releases (thanks, Bruce!). + Time System @@ -135,10 +1768,9 @@ These timing results are from running the regression test with the command Time System - 06:12 Pentium Pro 180, 32MB, Linux 2.0.30, gcc 2.7.2 -O2 -m486 + 06:12 Pentium Pro 180, 32MB, EIDE, Linux 2.0.30, gcc 2.7.2 -O2 -m486 12:06 P-100, 48MB, Linux 2.0.29, gcc 39:58 Sparc IPC 32MB, Solaris 2.5, gcc 2.7.2.1 -O -g
- diff --git a/doc/src/sgml/typeconv.sgml b/doc/src/sgml/typeconv.sgml new file mode 100644 index 0000000000000000000000000000000000000000..674bf843b6303e590fec4b53ad5dd4d46020088e --- /dev/null +++ b/doc/src/sgml/typeconv.sgml @@ -0,0 +1,653 @@ + +Type Conversion + + +SQL queries can, intentionally or not, require +mixing of different data types in the same expression. +Postgres has extensive facilities for +evaluating mixed-type expressions. + + +In many cases a user will not need +to understand the details of the type conversion mechanism. +However, the implicit conversions done by Postgres +can affect the apparent results of a query, and these results +can be tailored by a user or programmer +using explicit type coersion. + + +This chapter introduces the Postgres + type conversion mechanisms and conventions. +Refer to the relevant sections in the User's Guide and Programmer's Guide +for more information on specific data types and allowed functions and operators. + + +The Programmer's Guide has more details on the exact algorithms used for +implicit type conversion and coersion. + + +Overview + + +SQL is a strongly typed language. That is, every data item +has an associated data type which determines its behavior and allowed usage. +Postgres has an extensible type system which is +much more general and flexible than other RDBMS implementations. +Hence, most type conversion behavior in Postgres +should be governed by general rules rather than by ad-hoc heuristics to allow +mixed-type expressions to be meaningful, even with user-defined types. + + +The Postgres scanner/parser decodes lexical elements +into only five fundamental categories: integers, floats, strings, names, and keywords. +Most extended types are first tokenized into strings. The SQL +language definition allows specifying type names with strings, and this mechanism +is used by Postgres +to start the parser down the correct path. For example, the query + + +tgl=> SELECT text 'Origin' AS "Label", point '(0,0)' AS "Value"; +Label |Value +------+----- +Origin|(0,0) +(1 row) + + +has two strings, of type text and point. +If a type is not specified, then the placeholder type unknown +is assigned initially, to be resolved in later stages as described below. + + +There are four fundamental SQL constructs requiring +distinct type conversion rules in the Postgres +parser: + + + + +Operators + + + +Postgres allows expressions with +left- and right-unary (one argument) operators, +as well as binary (two argument) operators. + + + + +Function calls + + + +Much of the Postgres type system is built around a rich set of +functions. Function calls have one or more arguments which, for any specific query, +must be matched to the functions available in the system catalog. + + + + +Query targets + + + +SQL INSERT statements place the results of query into a table. The expressions +in the query must be matched up with, and perhaps converted to, the target columns of the insert. + + + + +UNION queries + + + +Since all select results from a UNION SELECT statement must appear in a single set of columns, the types +of each SELECT clause must be matched up and converted to a uniform set. + + + + + +Many of the general type conversion rules use simple conventions built on +the Postgres function and operator system tables. +There are some heuristics included in the conversion rules to better support +conventions for the SQL92 standard native types such as +smallint, integer, and float. + + +The Postgres parser uses the convention that all +type conversion functions take a single argument of the source type and are +named with the same name as the target type. Any function meeting this +criteria is considered to be a valid conversion function, and may be used +by the parser as such. This simple assumption gives the parser the power +to explore type conversion possibilities without hardcoding, allowing +extended user-defined types to use these same features transparently. + + +An additional heuristic is provided in the parser to allow better guesses +at proper behavior for SQL standard types. There are +five categories of types defined: boolean, string, numeric, geometric, +and user-defined. Each category, with the exception of user-defined, has +a "preferred type" which is used to resolve ambiguities in candidates. +Each "user-defined" type is its own "preferred type", so ambiguous +expressions (those with multiple candidate parsing solutions) +with only one user-defined type can resolve to a single best choice, while those with +multiple user-defined types will remain ambiguous and throw an error. + + +Ambiguous expressions which have candidate solutions within only one type category are +likely to resolve, while ambiguous expressions with candidates spanning multiple +categories are likely to throw an error and ask for clarification from the user. + + +Guidelines + + +All type conversion rules are designed with several principles in mind: + + + + +Implicit conversions should never have suprising or unpredictable outcomes. + + + +User-defined types, of which the parser has no apriori knowledge, should be +"higher" in the type heirarchy. In mixed-type expressions, native types shall always +be converted to a user-defined type (of course, only if conversion is necessary). + + + +User-defined types are not related. Currently, Postgres +does not have information available to it on relationships between types, other than +hardcoded heuristics for built-in types and implicit relationships based on available functions +in the catalog. + + + +There should be no extra overhead from the parser or executor +if a query does not need implicit type conversion. +That is, if a query is well formulated and the types already match up, then the query should proceed +without spending extra time in the parser and without introducing unnecessary implicit conversion +functions into the query. + + +Additionally, if a query usually requires an implicit conversion for a function, and +if then the user defines an explicit function with the correct argument types, the parser +should use this new function and will no longer do the implicit conversion using the old function. + + + +Operators + + +Conversion Procedure + + + +Operator Evaluation + + + + + +Check for an exact match in the pg_operator system catalog. + + + + +If one argument of a binary operator is unknown, +then assume it is the same type as the other argument. + + + +Reverse the arguments, and look for an exact match with an operator which +points to itself as being commutative. +If found, then reverse the arguments in the parse tree and use this operator. + + + + + +Look for the best match. + + + + +Make a list of all operators of the same name. + + + +If only one operator is in the list, use it if the input type can be coerced, +and throw an error if the type cannot be coerced. + + + +Keep all operators with the most explicit matches for types. Keep all if there +are no explicit matches and move to the next step. +If only one candidate remains, use it if the type can be coerced. + + + +If any input arguments are "unknown", categorize the input candidates as +boolean, numeric, string, geometric, or user-defined. If there is a mix of +categories, or more than one user-defined type, throw an error because +the correct choice cannot be deduced without more clues. +If only one category is present, then assign the "preferred type" +to the input column which had been previously "unknown". + + + +Choose the candidate with the most exact type matches, and which matches +the "preferred type" for each column category from the previous step. +If there is still more than one candidate, or if there are none, +then throw an error. + + + + + +Examples + + +Exponentiation Operator + + +There is only one exponentiation +operator defined in the catalog, and it takes float8 arguments. +The scanner assigns an initial type of int4 to both arguments +of this query expression: + +tgl=> select 2 ^ 3 AS "Exp"; +Exp +--- + 8 +(1 row) + + +So the parser does a type conversion on both operands and the query +is equivalent to + + +tgl=> select float8(2) ^ float8(3) AS "Exp"; +Exp +--- + 8 +(1 row) + + +or + + +tgl=> select 2.0 ^ 3.0 AS "Exp"; +Exp +--- + 8 +(1 row) + + + + +This last form has the least overhead, since no functions are called to do +implicit type conversion. This is not an issue for small queries, but may +have an impact on the performance of queries involving large tables. + + + +String Concatenation + + +A string-like syntax is used for working with string types as well as for +working with complex extended types. +Strings with unspecified type are matched with likely operator candidates. + + +One unspecified argument: + +tgl=> SELECT text 'abc' || 'def' AS "Text and Unknown"; +Text and Unknown +---------------- +abcdef +(1 row) + + + +In this case the parser looks to see if there is an operator taking text +for both arguments. Since there is, it assumes that the second argument should +be interpreted as of type text. + + +Concatenation on unspecified types: + +tgl=> SELECT 'abc' || 'def' AS "Unspecified"; +Unspecified +----------- +abcdef +(1 row) + + + +In this case there is no initial hint for which type to use, since no types +are specified in the query. So, the parser looks for all candidate operators +and finds that all arguments for all the candidates are string types. It chooses +the "preferred type" for strings, text, for this query. + + + +If a user defines a new type and defines an operator || to work +with it, then this query would no longer succeed as written. The parser would +now have candidate types from two categories, and could not decide which to use. + + + +Factorial + + +This example illustrates an interesting result. Traditionally, the +factorial operator is defined for integers only. The Postgres +operator catalog has only one entry for factorial, taking an integer operand. +If given a non-integer numeric argument, Postgres +will try to convert that argument to an integer for evaluation of the +factorial. + + +tgl=> select (4.3 !); +?column? +-------- + 24 +(1 row) + + + + +Of course, this leads to a mathematically suspect result, +since in principle the factorial of a non-integer is not defined. +However, the role of a database is not to teach mathematics, but +to be a tool for data manipulation. If a user chooses to take the +factorial of a floating point number, Postgres +will try to oblige. + + + +Functions + + + + +Function Evaluation + + + +Check for an exact match in the pg_proc system catalog. + + + +Look for the best match. + + + + +Make a list of all functions of the same name with the same number of arguments. + + + +If only one function is in the list, use it if the input types can be coerced, +and throw an error if the types cannot be coerced. + + + +Keep all functions with the most explicit matches for types. Keep all if there +are no explicit matches and move to the next step. +If only one candidate remains, use it if the type can be coerced. + + + +If any input arguments are "unknown", categorize the input candidate arguments as +boolean, numeric, string, geometric, or user-defined. If there is a mix of +categories, or more than one user-defined type, throw an error because +the correct choice cannot be deduced without more clues. +If only one category is present, then assign the "preferred type" +to the input column which had been previously "unknown". + + + +Choose the candidate with the most exact type matches, and which matches +the "preferred type" for each column category from the previous step. +If there is still more than one candidate, or if there are none, +then throw an error. + + + + + +Examples + + +Factorial Function + + +There is only one factorial function defined in the pg_proc catalog. +So the following query automatically converts the int2 argument +to int4: + + +tgl=> select int4fac(int2 '4'); +int4fac +------- + 24 +(1 row) + + +and is actually transformed by the parser to + +tgl=> select int4fac(int4(int2 '4')); +int4fac +------- + 24 +(1 row) + + + +Substring Function + + +There are two substr functions declared in pg_proc. However, +only one takes two arguments, of types text and int4. + + +If called with a string constant of unspecified type, the type is matched up +directly with the only candidate function type: + +tgl=> select substr('1234', 3); +substr +------ + 34 +(1 row) + + + +If the string is declared to be of type varchar, as might be the case +if it comes from a table, then the parser will try to coerce it to become text: + +tgl=> select substr(varchar '1234', 3); +substr +------ + 34 +(1 row) + +which is transformed by the parser to become + +tgl=> select substr(text(varchar '1234'), 3); +substr +------ + 34 +(1 row) + + + +There are some heuristics in the parser to optimize the relationship between the +char, varchar, and text types. +For this case, substr is called directly with the varchar string +rather than inserting an explicit conversion call. + + + +And, if the function is called with an int4, the parser will +try to convert that to text: + +tgl=> select substr(1234, 3); +substr +------ + 34 +(1 row) + +actually executes as + +tgl=> select substr(text(1234), 3); +substr +------ + 34 +(1 row) + + + +Query Targets + + + + +Target Evaluation + + + +Check for an exact match with the target. + + + +Try to coerce the expression directly to the target type if necessary. + + + +If the target is a fixed-length type (e.g. char or varchar +declared with a length) then try to find a sizing function of the same name +as the type taking two arguments, the first the type name and the second an +integer length. + + + + +Examples + + +<type>varchar</type> Storage + + +For a target column declared as varchar(4) the following query +ensures that the target is sized correctly: + + +tgl=> CREATE TABLE vv (v varchar(4)); +CREATE +tgl=> INSERT INTO vv SELECT 'abc' || 'def'; +INSERT 392905 1 +tgl=> select * from vv; +v +---- +abcd +(1 row) + + + + +UNION Queries + + +The UNION construct is somewhat different in that it must match up +possibly dissimilar types to become a single result set. + + +UNION Evaluation + + + +Check for identical types for all results. + + + +Coerce each result from the UNION clauses to match the type of the +first SELECT clause or the target column. + + + + +Examples + + +Underspecified Types + + + +tgl=> SELECT text 'a' AS "Text" UNION SELECT 'b'; +Text +---- +a +b +(2 rows) + + + +Simple UNION + + + +tgl=> SELECT 1.2 AS Float8 UNION SELECT 1; +Float8 +------ + 1 + 1.2 +(2 rows) + + + +Transposed UNION + + +The types of the union are forced to match the types of +the first/top clause in the union: + + +tgl=> SELECT 1 AS "All integers" +tgl-> UNION SELECT '2.2'::float4 +tgl-> UNION SELECT 3.3; +All integers +------------ + 1 + 2 + 3 +(3 rows) + + + +An alternate parser strategy could be to choose the "best" type of the bunch, but +this is more difficult because of the nice recursion technique used in the +parser. However, the "best" type is used when selecting into +a table: + + +tgl=> CREATE TABLE ff (f float); +CREATE +tgl=> INSERT INTO ff +tgl-> SELECT 1 +tgl-> UNION SELECT '2.2'::float4 +tgl-> UNION SELECT 3.3; +INSERT 0 3 +tgl=> SELECT f AS "Floating point" from ff; + Floating point +---------------- + 1 +2.20000004768372 + 3.3 +(3 rows) + + + diff --git a/doc/src/sgml/user.sgml b/doc/src/sgml/user.sgml index 151dd84b54e552bd9868e609ded9d8fc71260b7a..c6d18b9963e04211f3ed95d515040d79ce5bcdcd 100644 --- a/doc/src/sgml/user.sgml +++ b/doc/src/sgml/user.sgml @@ -11,6 +11,9 @@ + + + @@ -92,6 +95,9 @@ It provides SQL92/SQL3 language support, &environ; &manage; &datatype; +&oper; +&func; +&typeconv; &array; &inherit; &query-ug;