From e894c61836e4b967f7ec65358fdaed2ba86ed238 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 12 Apr 2020 18:03:20 -0400 Subject: [PATCH] Doc: introduce new layout for tables of functions and operators. We've long fought with the draconian space limitations of our traditional table layout for describing SQL functions and operators. This commit introduces a new approach, though so far I've only applied it to a few of those tables. The new way makes use of DocBook's support for different layouts in different rows of a table, and allows the descriptions and examples for a function or operator to run to several lines without as much ugliness and wasted space as before. The core layout concept is now Name Signature Description Example Example Result so that a function or operator really has three table rows not one, but we group them to look like one row by having the name column have only one entry for all three rows. (Actually, there could be four or more rows if you wanted to have more than one example, which is another thing that was painful before but works easily now.) This is handled by a "morerows" annotation on the name entry, which isn't perfect (notably, the toolchain is not smart enough to avoid breaking these row groups across PDF pages) but there seems no better solution in DocBook. The name column is normally fairly narrow, allowing plenty of space for the other column(s), and not wasting too much space when one of the other components runs to multiple lines. The varying row layout is managed by defining named "spans" and then tagging entries with a "spanname" of "name", "sig", "desc", "example", or "exresult". This provides a bit of semantic annotation to go with the formatting improvement, which seems like a good thing. (It seems that we have to re-define these spans afresh for each table, which is annoying, but it's not any worse than the duplication involved in the table headers. At least that gives us an opportunity to vary the relative column widths per-table, which is handy since function tables sometimes need much wider name columns than operator tables.) Signature entries should be written in the style fname(typename ...) typename The tag produces a right arrow before the result type name. (I'll document that convention in a user-visible place later.) While this provides significantly more horizontal space than before for examples, it's still true that PDF output is a lot narrower than typical webpage viewing windows, so some examples need to be broken in places where there is no whitespace. I've added &zwsp; markers in suitable places to allow the tables to render warning-free in PDF. I've so far converted only the date/time operator, date/time function, and enum function tables in sections 9.9 and 9.10; these were chosen to provide a reasonable sample of the formatting problems that need to be solved. Assuming that this looks good on the website and doesn't provoke howls of anguish, I'll work on the other similar tables in the near future. There's a moderate amount of new editorial content in this patch along with the raw formatting changes; for instance I had to write text descriptions for operators that lacked them. I failed to resist the temptation to improve some other descriptions and examples, too. Patch by me, with thanks to Alexander Lakhin for assistance with figuring out some formatting issues. Discussion: https://postgr.es/m/9326.1581457869@sss.pgh.pa.us --- doc/src/sgml/func.sgml | 1028 +++++++++++++++++++--------- doc/src/sgml/stylesheet-common.xsl | 6 + doc/src/sgml/stylesheet-fo.xsl | 7 + 3 files changed, 711 insertions(+), 330 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 5e5bfddf7c..7a270eb0ab 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -6744,127 +6744,256 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}'); Date/Time Operators + + + + + + + + - Operator - Example - Result + Operator + Signature + + + Description + + + Example + Example Result - + - date '2001-09-28' + integer '7' - date '2001-10-05' + + + date + integer + date - - + - date '2001-09-28' + interval '1 hour' - timestamp '2001-09-28 01:00:00' + Add a number of days to a date - - + - date '2001-09-28' + time '03:00' - timestamp '2001-09-28 03:00:00' + date '2001-09-28' + 7 + 2001-10-05 - + - interval '1 day' + interval '1 hour' - interval '1 day 01:00:00' + + + date + interval + timestamp + + + Add an interval to a date + + + date '2001-09-28' + interval '1 hour' + 2001-09-28 01:00:00 - + - timestamp '2001-09-28 01:00' + interval '23 hours' - timestamp '2001-09-29 00:00:00' + + + date + time + timestamp + + + Add a time-of-day to a date + + + date '2001-09-28' + time '03:00' + 2001-09-28 03:00:00 - + - time '01:00' + interval '3 hours' - time '04:00:00' + + + interval + interval + interval + + + Add intervals + + + interval '1 day' + interval '1 hour' + 1 day 01:00:00 - - - - interval '23 hours' - interval '-23:00:00' + + + timestamp + interval + timestamp + + + Add an interval to a timestamp + + + timestamp '2001-09-28 01:00' + interval '23 hours' + 2001-09-29 00:00:00 - - - date '2001-10-01' - date '2001-09-28' - integer '3' (days) + + + time + interval + time + + + Add an interval to a time + + + time '01:00' + interval '3 hours' + 04:00:00 - - - date '2001-10-01' - integer '7' - date '2001-09-24' + - + - interval + interval + + + Negate an interval + + + - interval '23 hours' + -23:00:00 - - - date '2001-09-28' - interval '1 hour' - timestamp '2001-09-27 23:00:00' + - + date - date + integer + + + Subtract dates + + + date '2001-10-01' - date '2001-09-28' + 3 - - - time '05:00' - time '03:00' - interval '02:00:00' + - + date - integer + date + + + Subtract a number of days from a date + + + date '2001-10-01' - 7 + 2001-09-24 - - - time '05:00' - interval '2 hours' - time '03:00:00' + - + date - interval + timestamp + + + Subtract an interval from a date + + + date '2001-09-28' - interval '1 hour' + 2001-09-27 23:00:00 - - - timestamp '2001-09-28 23:00' - interval '23 hours' - timestamp '2001-09-28 00:00:00' + - + time - time + interval + + + Subtract times + + + time '05:00' - time '03:00' + 02:00:00 - - - interval '1 day' - interval '1 hour' - interval '1 day -01:00:00' + - + time - interval + time + + + Subtract an interval from a time + + + time '05:00' - interval '2 hours' + 03:00:00 - - - timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00' - interval '1 day 15:00:00' + - + timestamp - interval + timestamp + + + Subtract an interval from a timestamp + + + timestamp '2001-09-28 23:00' - interval '23 hours' + 2001-09-28 00:00:00 - * - 900 * interval '1 second' - interval '00:15:00' + - + interval - interval + interval + + + Subtract intervals + + + interval '1 day' - interval '1 hour' + 1 day -01:00:00 - * - 21 * interval '1 day' - interval '21 days' + - + timestamp - timestamp + interval + + + Subtract timestamps + + + timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00' + 1 day 15:00:00 - * - double precision '3.5' * interval '1 hour' - interval '03:30:00' + * + double precision * interval + interval + + + Multiply an interval by a scalar + + + 900 * interval '1 second' + 00:15:00 + + + 21 * interval '1 day' + 21 days + + + 3.5 * interval '1 hour' + 03:30:00 - / - interval '1 hour' / double precision '1.5' - interval '00:40:00' + / + interval / double precision + interval + + + Divide an interval by a scalar + + + interval '1 hour' / 1.5 + 00:40:00 @@ -6872,471 +7001,677 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}'); Date/Time Functions - + + + + + + + + + - Function - Return Type - Description - Example - Result + Function + Signature + + + Description + + + Example + Example Result - + age - age(timestamp, timestamp) + age - interval - Subtract arguments, producing a symbolic result that + age(timestamp, timestamp) + interval + + + Subtract arguments, producing a symbolic result that uses years and months, rather than just days - age(timestamp '2001-04-10', timestamp '1957-06-13') - 43 years 9 mons 27 days + + + age(timestamp '2001-04-10', timestamp '1957-06-13') + 43 years 9 mons 27 days - age(timestamp) - interval - Subtract from current_date (at midnight) - age(timestamp '1957-06-13') - 43 years 8 mons 3 days + age + age(timestamp) + interval + + + Subtract from current_date (at midnight) + + + age(timestamp '1957-06-13') + variable - + clock_timestamp - clock_timestamp() + clock_timestamp - timestamp with time zone - Current date and time (changes during statement execution); + clock_timestamp() + timestamp with time zone + + + Current date and time (changes during statement execution); see - - + + + clock_timestamp() + variable - + current_date - current_date + current_date - date - Current date; + current_date + date + + + Current date; see - - + + + current_date + variable - + current_time - current_time + current_time - time with time zone - Current time of day; + current_time + time with time zone + + + Current time of day; see - - + + + current_time + variable - + current_time + current_time(integer) + time with time zone + + + Current time of day, with limited precision; + see + + + + current_time(2) + variable + + + + current_timestamp - current_timestamp + current_timestamp - timestamp with time zone - Current date and time (start of current transaction); + current_timestamp + timestamp with time zone + + + Current date and time (start of current transaction); see - - + + + current_timestamp + variable - + current_timestamp + current_timestamp(integer) + timestamp with time zone + + + Current date and time (start of current transaction), with limited precision; + see + + + + current_timestamp(0) + variable + + + + date_part - date_part(text, timestamp) + date_part - double precision - Get subfield (equivalent to extract); + date_part(text, timestamp) + double precision + + + Get timestamp subfield (equivalent to extract); see - date_part('hour', timestamp '2001-02-16 20:38:40') - 20 + + + date_part('hour', timestamp '2001-02-16 20:38:40') + 20 - date_part(text, interval) - double precision - Get subfield (equivalent to + date_part + date_part(text, interval) + double precision + + + Get interval subfield (equivalent to extract); see - date_part('month', interval '2 years 3 months') - 3 + + + date_part('month', interval '2 years 3 months') + 3 - + date_trunc - date_trunc(text, timestamp) + date_trunc - timestamp - Truncate to specified precision; see + date_trunc(text, timestamp) + timestamp + + + Truncate to specified precision; see - date_trunc('hour', timestamp '2001-02-16 20:38:40') - 2001-02-16 20:00:00 + + + date_trunc('hour', timestamp '2001-02-16 20:38:40') + 2001-02-16 20:00:00 - date_trunc(text, timestamp with time zone, text) - timestamp with time zone - Truncate to specified precision in the specified time zone; see + date_trunc + date_trunc(text, timestamp with time zone, text) + timestamp with time zone + + + Truncate to specified precision in the specified time zone; see - date_trunc('day', timestamptz '2001-02-16 20:38:40+00', 'Australia/Sydney') - 2001-02-16 13:00:00+00 + + + date_trunc('day', timestamptz '2001-02-16 20:38:40+00', 'Australia/Sydney') + 2001-02-16 13:00:00+00 - date_trunc(text, interval) - interval - Truncate to specified precision; see + date_trunc + date_trunc(text, interval) + interval + + + Truncate to specified precision; see - date_trunc('hour', interval '2 days 3 hours 40 minutes') - 2 days 03:00:00 + + + date_trunc('hour', interval '2 days 3 hours 40 minutes') + 2 days 03:00:00 - + extract - extract(field from - timestamp) + extract - double precision - Get subfield; see + extract(field from timestamp) + double precision + + + Get timestamp subfield; see - extract(hour from timestamp '2001-02-16 20:38:40') - 20 + + + extract(hour from timestamp '2001-02-16 20:38:40') + 20 - extract(field from - interval) - double precision - Get subfield; see + extract + extract(field from interval) + double precision + + + Get interval subfield; see - extract(month from interval '2 years 3 months') - 3 + + + extract(month from interval '2 years 3 months') + 3 - + isfinite - isfinite(date) + isfinite - boolean - Test for finite date (not +/-infinity) - isfinite(date '2001-02-16') - true + isfinite(date) + boolean + + + Test for finite date (not +/-infinity) + + + isfinite(date '2001-02-16') + true - isfinite(timestamp) - boolean - Test for finite time stamp (not +/-infinity) - isfinite(timestamp '2001-02-16 21:28:30') - true + isfinite + isfinite(timestamp) + boolean + + + Test for finite timestamp (not +/-infinity) + + + isfinite(timestamp 'infinity') + false - isfinite(interval) - boolean - Test for finite interval - isfinite(interval '4 hours') - true + isfinite + isfinite(interval) + boolean + + + Test for finite interval (currently always true) + + + isfinite(interval '4 hours') + true - + justify_days - justify_days(interval) + justify_days - interval - Adjust interval so 30-day time periods are represented as months - justify_days(interval '35 days') - 1 mon 5 days + justify_days(interval) + interval + + + Adjust interval so 30-day time periods are represented as months + + + justify_days(interval '35 days') + 1 mon 5 days - + justify_hours - justify_hours(interval) + justify_hours - interval - Adjust interval so 24-hour time periods are represented as days - justify_hours(interval '27 hours') - 1 day 03:00:00 + justify_hours(interval) + interval + + + Adjust interval so 24-hour time periods are represented as days + + + justify_hours(&zwsp;interval '27 hours') + 1 day 03:00:00 - + justify_interval - justify_interval(interval) + justify_interval - interval - Adjust interval using justify_days and justify_hours, with additional sign adjustments - justify_interval(interval '1 mon -1 hour') - 29 days 23:00:00 + justify_interval(interval) + interval + + + Adjust interval using justify_days and justify_hours, with additional sign adjustments + + + justify_interval(&zwsp;interval '1 mon -1 hour') + 29 days 23:00:00 - + localtime - localtime + localtime - time - Current time of day; + localtime + time + + + Current time of day; see - - + + + localtime + variable - + localtime + localtime(integer) + time + + + Current time of day, with limited precision; + see + + + + localtime(0) + variable + + + + localtimestamp - localtimestamp + localtimestamp - timestamp - Current date and time (start of current transaction); + localtimestamp + timestamp + + + Current date and time (start of current transaction); see - - + + + localtimestamp + variable - + localtimestamp + localtimestamp(integer) + timestamp + + + Current date and time (start of current + transaction), with limited precision; + see + + + + localtimestamp(2) + variable + + + + make_date - - - make_date(year int, - month int, - day int) - - + make_date - date - + make_date(year int, + month int, + day int) + date + + + Create date from year, month and day fields - make_date(2013, 7, 15) - 2013-07-15 + + + make_date(2013, 7, 15) + 2013-07-15 - - + make_interval - - - make_interval(years int DEFAULT 0, - months int DEFAULT 0, - weeks int DEFAULT 0, - days int DEFAULT 0, - hours int DEFAULT 0, - mins int DEFAULT 0, - secs double precision DEFAULT 0.0) - - + make_interval - interval - + make_interval( year int + , month int + , week int + , day int + , hour int + , min int + , sec double precision + ) + interval + + + Create interval from years, months, weeks, days, hours, minutes and - seconds fields + seconds fields, each of which can default to zero - make_interval(days => 10) - 10 days + + + make_interval(days => 10) + 10 days - + make_time - - - make_time(hour int, - min int, - sec double precision) - - + make_time - time - + make_time(hour int, + min int, + sec double precision) + time + + + Create time from hour, minute and seconds fields - make_time(8, 15, 23.5) - 08:15:23.5 + + + make_time(8, 15, 23.5) + 08:15:23.5 - + make_timestamp - - - make_timestamp(year int, - month int, - day int, - hour int, - min int, - sec double precision) - - + make_timestamp - timestamp - + make_timestamp(year int, + month int, + day int, + hour int, + min int, + sec double precision) + timestamp + + + Create timestamp from year, month, day, hour, minute and seconds fields - make_timestamp(2013, 7, 15, 8, 15, 23.5) - 2013-07-15 08:15:23.5 + + + make_timestamp(&zwsp;2013, 7, 15, 8, 15, 23.5) + 2013-07-15 08:15:23.5 - + make_timestamptz - - - make_timestamptz(year int, - month int, - day int, - hour int, - min int, - sec double precision, - timezone text ) - - + make_timestamptz - timestamp with time zone - + make_timestamptz(year int, + month int, + day int, + hour int, + min int, + sec double precision + , timezone text ) + timestamp with time zone + + + Create timestamp with time zone from year, month, day, hour, minute and seconds fields; if timezone is not specified, the current time zone is used - make_timestamptz(2013, 7, 15, 8, 15, 23.5) - 2013-07-15 08:15:23.5+01 + + + make_timestamptz(&zwsp;2013, 7, 15, 8, 15, 23.5) + 2013-07-15 08:15:23.5+01 - + now - now() + now - timestamp with time zone - Current date and time (start of current transaction); + now() + timestamp with time zone + + + Current date and time (start of current transaction); see - - + + + now() + variable - + statement_timestamp - statement_timestamp() + statement_timestamp - timestamp with time zone - Current date and time (start of current statement); + statement_timestamp() + timestamp with time zone + + + Current date and time (start of current statement); see - - + + + statement_timestamp() + variable - + timeofday - timeofday() + timeofday - text - Current date and time + timeofday() + text + + + Current date and time (like clock_timestamp, but as a text string); see - - + + + timeofday() + variable - + transaction_timestamp - transaction_timestamp() + transaction_timestamp - timestamp with time zone - Current date and time (start of current transaction); + transaction_timestamp() + timestamp with time zone + + + Current date and time (start of current transaction); see - - - + transaction_&zwsp;timestamp() + variable + + + to_timestamp - to_timestamp(double precision) + to_timestamp - timestamp with time zone - Convert Unix epoch (seconds since 1970-01-01 00:00:00+00) to + to_timestamp(double precision) + timestamp with time zone + + + Convert Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp - to_timestamp(1284352323) - 2010-09-13 04:32:03+00 + + + to_timestamp(&zwsp;1284352323) + 2010-09-13 04:32:03+00 @@ -8310,52 +8645,83 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
Enum Support Functions - + + + + + + + + + - Function - Description - Example - Example Result + Function + Signature + + + Description + + + Example + Example Result - - - enum_first - - enum_first(anyenum) + + + enum_first + + enum_first - Returns the first value of the input enum type - enum_first(null::rainbow) - red + enum_first(anyenum) anyenum - - - enum_last - - enum_last(anyenum) + Returns the first value of the input enum type + + + enum_first(&zwsp;null::rainbow) + red + + + + + enum_last + + enum_last - Returns the last value of the input enum type - enum_last(null::rainbow) - purple + enum_last(anyenum) anyenum - - - enum_range - - enum_range(anyenum) + Returns the last value of the input enum type + + + enum_last(&zwsp;null::rainbow) + purple + + + + + enum_range + + enum_range - Returns all values of the input enum type in an ordered array - enum_range(null::rainbow) - {red,orange,yellow,green,blue,purple} + enum_range(anyenum) anyarray - enum_range(anyenum, anyenum) - + Returns all values of the input enum type in an ordered array + + + enum_range(&zwsp;null::rainbow) + {red,orange,yellow,&zwsp;green,blue,purple} + + + enum_range + enum_range(anyenum, anyenum) anyarray + + + Returns the range between the two given enum values, as an ordered array. The values must be from the same enum type. If the first parameter is null, the result will start with the first value of @@ -8363,16 +8729,18 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple If the second parameter is null, the result will end with the last value of the enum type. - enum_range('orange'::rainbow, 'green'::rainbow) - {orange,yellow,green} - enum_range(NULL, 'green'::rainbow) - {red,orange,yellow,green} + enum_range(&zwsp;'orange'::rainbow, 'green'::rainbow) + {orange,yellow,green} + + + enum_range(NULL, 'green'::rainbow) + {red,orange,yellow,&zwsp;green} - enum_range('orange'::rainbow, NULL) - {orange,yellow,green,blue,purple} + enum_range(&zwsp;'orange'::rainbow, NULL) + {orange,yellow,green,&zwsp;blue,purple} @@ -8384,7 +8752,7 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple only about its declared data type. Either null or a specific value of the type can be passed, with the same result. It is more common to apply these functions to a table column or function argument than to - a hardwired type name as suggested by the examples. + a hardwired type name as used in the examples. diff --git a/doc/src/sgml/stylesheet-common.xsl b/doc/src/sgml/stylesheet-common.xsl index e148c9057f..a13565e601 100644 --- a/doc/src/sgml/stylesheet-common.xsl +++ b/doc/src/sgml/stylesheet-common.xsl @@ -49,6 +49,12 @@ + + + → + + + diff --git a/doc/src/sgml/stylesheet-fo.xsl b/doc/src/sgml/stylesheet-fo.xsl index ea754084be..2aaae82092 100644 --- a/doc/src/sgml/stylesheet-fo.xsl +++ b/doc/src/sgml/stylesheet-fo.xsl @@ -63,6 +63,13 @@ + + + + + + + -- 2.39.5