Commit Graph

88 Commits

Author SHA1 Message Date
Tom Lane 463b808e75 Doc: correct nitpicky mistakes in array_position/array_positions examples.
Daniel Gustafsson and Erik Rijkers, per report from nick@cleaton

Discussion: https://postgr.es/m/159275646273.679.16940709892308114570@wrigleys.postgresql.org
2020-06-25 13:28:30 -04:00
Bruce Momjian f77de4b0c0 docs: remove use of escape strings and use bytea hex output
standard_conforming_strings defaulted to 'on' in PG 9.1.
bytea_output defaulted to 'hex' in PG 9.0.

Reported-by: André Hänsel

Discussion: https://postgr.es/m/12e601d447ac$345994a0$9d0cbde0$@webkr.de

Backpatch-through: 9.3
2018-09-21 19:55:07 -04:00
Peter Eisentraut 3c49c6facb Convert documentation to DocBook XML
Since some preparation work had already been done, the only source
changes left were changing empty-element tags like <xref linkend="foo">
to <xref linkend="foo"/>, and changing the DOCTYPE.

The source files are still named *.sgml, but they are actually XML files
now.  Renaming could be considered later.

In the build system, the intermediate step to convert from SGML to XML
is removed.  Everything is build straight from the source files again.
The OpenSP (or the old SP) package is no longer needed.

The documentation toolchain instructions are updated and are much
simpler now.

Peter Eisentraut, Alexander Lakhin, Jürgen Purtz
2017-11-23 09:44:28 -05:00
Peter Eisentraut c29c578908 Don't use SGML empty tags
For DocBook XML compatibility, don't use SGML empty tags (</>) anymore,
replace by the full tag name.  Add a warning option to catch future
occurrences.

Alexander Lakhin, Jürgen Purtz
2017-10-17 15:10:33 -04:00
Tom Lane c12d570fa1 Support arrays over domains.
Allowing arrays with a domain type as their element type was left un-done
in the original domain patch, but not for any very good reason.  This
omission leads to such surprising results as array_agg() not working on
a domain column, because the parser can't identify a suitable output type
for the polymorphic aggregate.

In order to fix this, first clean up the APIs of coerce_to_domain() and
some internal functions in parse_coerce.c so that we consistently pass
around a CoercionContext along with CoercionForm.  Previously, we sometimes
passed an "isExplicit" boolean flag instead, which is strictly less
information; and coerce_to_domain() didn't even get that, but instead had
to reverse-engineer isExplicit from CoercionForm.  That's contrary to the
documentation in primnodes.h that says that CoercionForm only affects
display and not semantics.  I don't think this change fixes any live bugs,
but it makes things more consistent.  The main reason for doing it though
is that now build_coercion_expression() receives ccontext, which it needs
in order to be able to recursively invoke coerce_to_target_type().

Next, reimplement ArrayCoerceExpr so that the node does not directly know
any details of what has to be done to the individual array elements while
performing the array coercion.  Instead, the per-element processing is
represented by a sub-expression whose input is a source array element and
whose output is a target array element.  This simplifies life in
parse_coerce.c, because it can build that sub-expression by a recursive
invocation of coerce_to_target_type().  The executor now handles the
per-element processing as a compiled expression instead of hard-wired code.
The main advantage of this is that we can use a single ArrayCoerceExpr to
handle as many as three successive steps per element: base type conversion,
typmod coercion, and domain constraint checking.  The old code used two
stacked ArrayCoerceExprs to handle type + typmod coercion, which was pretty
inefficient, and adding yet another array deconstruction to do domain
constraint checking seemed very unappetizing.

In the case where we just need a single, very simple coercion function,
doing this straightforwardly leads to a noticeable increase in the
per-array-element runtime cost.  Hence, add an additional shortcut evalfunc
in execExprInterp.c that skips unnecessary overhead for that specific form
of expression.  The runtime speed of simple cases is within 1% or so of
where it was before, while cases that previously required two levels of
array processing are significantly faster.

Finally, create an implicit array type for every domain type, as we do for
base types, enums, etc.  Everything except the array-coercion case seems
to just work without further effort.

Tom Lane, reviewed by Andrew Dunstan

Discussion: https://postgr.es/m/9852.1499791473@sss.pgh.pa.us
2017-09-30 13:40:56 -04:00
Peter Eisentraut 1c53f612bc Escape < and & in SGML
This is not required in SGML, but will be in XML, so this is a step to
prepare for the conversion to XML.  (It is still not required to escape
>, but we did it here in some cases for symmetry.)

Add a command-line option to osx/onsgmls calls to warn about unescaped
occurrences in the future.

Author: Alexander Law <exclusion@gmail.com>
Author: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2017-09-06 11:22:43 -04:00
Tom Lane 6efbded6e4 Allow omitting one or both boundaries in an array slice specifier.
Omitted boundaries represent the upper or lower limit of the corresponding
array subscript.  This allows simpler specification of many common
use-cases.

(Revised version of commit 9246af6799)

YUriy Zhuravlev
2015-12-22 21:05:29 -05:00
Teodor Sigaev bbbd807097 Revert 9246af6799 because
I miss too much. Patch is returned to commitfest process.
2015-12-18 21:35:22 +03:00
Teodor Sigaev 9246af6799 Allow to omit boundaries in array subscript
Allow to omiy lower or upper or both boundaries in array subscript
for selecting slice of array.

Author: YUriy Zhuravlev
2015-12-18 15:18:58 +03:00
Tom Lane e4f29ce323 Improve documentation about array concat operator vs. underlying functions.
The documentation implied that there was seldom any reason to use the
array_append, array_prepend, and array_cat functions directly.  But that's
not really true, because they can help make it clear which case is meant,
which the || operator can't do since it's overloaded to represent all three
cases.  Add some discussion and examples illustrating the potentially
confusing behavior that can ensue if the parser misinterprets what was
meant.

Per a complaint from Michael Herold.  Back-patch to 9.2, which is where ||
started to behave this way.
2015-07-09 18:50:31 -04:00
Alvaro Herrera 97690ea6e8 Change array_offset to return subscripts, not offsets
... and rename it and its sibling array_offsets to array_position and
array_positions, to account for the changed behavior.

Having the functions return subscripts better matches existing practice,
and is better suited to using the result value as a subscript into the
array directly.  For one-based arrays, the new definition is identical
to what was originally committed.

(We use the term "subscript" in the documentation, which is what we use
whenever we talk about arrays; but the functions themselves are named
using the word "position" to match the standard-defined POSITION()
functions.)

Author: Pavel Stěhule
Behavioral problem noted by Dean Rasheed.
2015-03-30 16:13:21 -03:00
Alvaro Herrera 13dbc7a824 array_offset() and array_offsets()
These functions return the offset position or positions of a value in an
array.

Author: Pavel Stěhule
Reviewed by: Jim Nasby
2015-03-18 16:01:34 -03:00
Robert Haas 01f7808b3e Add a cardinality function for arrays.
Unlike our other array functions, this considers the total number of
elements across all dimensions, and returns 0 rather than NULL when the
array has no elements.  But it seems that both of those behaviors are
almost universally disliked, so hopefully that's OK.

Marko Tiikkaja, reviewed by Dean Rasheed and Pavel Stehule
2014-01-21 12:38:53 -05:00
Robert Haas 6ef5baf8b1 Document that && can be used to search arrays.
Also, add some cross-links to the indexing documentation, so it's easier
to notice that && and other array operators have index support.

Ryan Kelly, edited by me.
2012-06-22 08:59:41 -04:00
Bruce Momjian a20bc9c866 Use proper SGML doc entities rather than angle-brackets.
Marco Nenciarini
2011-06-02 19:33:16 -04:00
Bruce Momjian 7a8f43968a In docs, rename "backwards compatibility" to "backward compatibility"
for consistency.
2011-03-11 14:33:10 -05:00
Bruce Momjian ad76242633 remove tags. 2011-02-06 18:44:43 -05:00
Magnus Hagander 9f2e211386 Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
Tom Lane c30446b9c9 Proofreading for Bruce's recent round of documentation proofreading.
Most of those changes were good, but some not so good ...
2009-06-17 21:58:49 +00:00
Bruce Momjian ba36c48e39 Proofreading adjustments for first two parts of documentation (Tutorial
and SQL).
2009-04-27 16:27:36 +00:00
Peter Eisentraut f98f6ee064 array_length() function, and for SQL compatibility also cardinality()
function as a special case.

This version still has the suspicious behavior of returning null for an
empty array (rather than zero), but this may need a wholesale revision of
empty array behavior, currently under discussion.

Jim Nasby, Robert Haas, Peter Eisentraut
2008-11-12 13:09:28 +00:00
Peter Eisentraut f7ad874ca8 Since SQL:2003, the array size specification in the SQL ARRAY syntax has
been optional.
2008-10-29 11:24:53 +00:00
Alvaro Herrera 1fcb977a13 Add generate_subscripts, a series-generation function which generates an
array's subscripts.

Pavel Stehule, some editorialization by me.
2008-04-28 14:48:58 +00:00
Alvaro Herrera a1d479f518 Add SGML ID attributes to the arrays subsections, and a few index entries for
them.
2008-04-27 04:33:27 +00:00
Tom Lane 2d013c41a3 Fix bad spelling and worse grammar in recent doc commits. Propagate
pg_dump --ignore-version comments into pg_dumpall and pg_restore pages.
2008-03-26 16:34:47 +00:00
Bruce Momjian 9469d083e5 Improve documentation for odd array slice behavior. 2008-03-26 14:43:20 +00:00
Tom Lane 04d919a11a Fix array_dims() example to be consistent with the data previously shown.
Christian Rossow
2007-06-07 14:49:56 +00:00
Tom Lane bc8036fc66 Support arrays of composite types, including the rowtypes of regular tables
and views (but not system catalogs, nor sequences or toast tables).  Get rid
of the hardwired convention that a type's array type is named exactly "_type",
instead using a new column pg_type.typarray to provide the linkage.  (It still
will be named "_type", though, except in odd corner cases such as
maximum-length type names.)

Along the way, make tracking of owner and schema dependencies for types more
uniform: a type directly created by the user has these dependencies, while a
table rowtype or auto-generated array type does not have them, but depends on
its parent object instead.

David Fetter, Andrew Dunstan, Tom Lane
2007-05-11 17:57:14 +00:00
Tom Lane 146c83c045 Fix some now-obsolete comments about the space used by various data
types.
2007-04-06 19:22:38 +00:00
Tom Lane 50acd427a5 Fix broken markup, improve wording. 2007-03-02 06:01:01 +00:00
Bruce Momjian ff0d71e263 Spell check on array patch. 2007-02-20 14:54:47 +00:00
Bruce Momjian 1b52359d90 Update array slice documentation to be clearer. 2007-02-20 14:34:25 +00:00
Bruce Momjian 09a9f10e7f Consistenly use colons before '<programlisting>' blocks, where
appropriate.
2007-02-01 00:28:19 +00:00
Bruce Momjian a134ee3379 Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:

        may - permission, "You may borrow my rake."

        can - ability, "I can lift that log."

        might - possibility, "It might rain today."

Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice.  Similarly, "It may crash" is better stated, "It might crash".

Also update two error messages mentioned in the documenation to match.
2007-01-31 20:56:20 +00:00
Bruce Momjian 1a62813464 Add missing colon. 2007-01-31 04:12:01 +00:00
Bruce Momjian 4ed9f1d9b7 Update documentation for backslashes to mention escape string syntax
more, and standard_conforming_strings less, because in the future non-E
strings will not treat backslashes specially.

Also use E'' strings where backslashes are used in examples. (The
existing examples would have drawn warnings.)

Backpatch to 8.2.X.
2007-01-30 22:29:23 +00:00
Tom Lane 352a56ba68 Allow assignment to array elements not contiguous with those already
present; intervening positions are filled with nulls.  This behavior
is required by SQL99 but was not implementable before 8.2 due to lack
of support for nulls in arrays.  I have only made it work for the
one-dimensional case, which is all that SQL99 requires.  It seems quite
complex to get it right in higher dimensions, and since we never allowed
extension at all in higher dimensions, I think that must count as a
future feature addition not a bug fix.
2006-09-29 21:22:21 +00:00
Bruce Momjian 12049d343e Revert documentation mention of array dimension checking, in next paragraph. 2006-05-09 23:12:54 +00:00
Bruce Momjian 0c9fab6c3b Mention array dimmensions are not enforced either. 2006-05-09 16:31:23 +00:00
Bruce Momjian efe3de07e9 Removes or minimizes some documentation mentions of backward
compatibility for release 7.2 and earlier.  I have not altered any
mentions of release 7.3 or later.  The release notes were not modified,
so the changes are still documented, just not in the main docs.
2006-04-23 03:39:52 +00:00
Tom Lane 1e9a1a70ad Change array_push and array_cat so that they retain the lower bound of
the array (for array_push) or higher-dimensional array (for array_cat)
rather than decrementing it as before.  This avoids generating lower
bounds other than one for any array operation within the SQL spec.  Per
recent discussion.
Interestingly, this seems to have been the original behavior, because
while updating the docs I noticed that a large fraction of relevant
examples were *wrong* for the old behavior and are now right.  Is it
worth correcting this in the back-branch docs?
2005-11-19 01:50:08 +00:00
Tom Lane cecb607559 Make SQL arrays support null elements. This commit fixes the core array
functionality, but I still need to make another pass looking at places
that incidentally use arrays (such as ACL manipulation) to make sure they
are null-safe.  Contrib needs work too.
I have not changed the behaviors that are still under discussion about
array comparison and what to do with lower bounds.
2005-11-17 22:14:56 +00:00
Peter Eisentraut 39dfbe5791 Spellchecking run, final cleanups 2005-11-04 23:14:02 +00:00
Tom Lane 03381695c6 Avoid referring to a specific version of the SQL standard except where
necessary, and be careful to refer to the right version where it is
useful to do so.  This partially reverts an ill-considered search and
replace from a few months ago.
2005-11-04 02:56:31 +00:00
Neil Conway c3f1b0f4dd This doc patch replaces all inappropriate references to SQL:1999 when it
is used as if it were the latest (and/or still valid) SQL standard.
SQL:2003 is used in its place. Patch from Simon Riggs.
2005-07-14 06:17:36 +00:00
Tom Lane e507399790 Document array behavior for out-of-range subscripts. 2005-02-06 20:59:30 +00:00
Tom Lane f8ffb60492 A small pass of docs review and copy-editing. 2004-12-23 05:37:40 +00:00
Peter Eisentraut 5ec30faee6 Spell checker run 2004-12-13 18:05:10 +00:00
Peter Eisentraut 49cbef7947 Update of conformance information to SQL:2003
by Troels Arvin, Simon Riggs, Elein Mustain

Make spelling of SQL standard names uniform.
2004-11-27 21:27:08 +00:00
Neil Conway ec7a6bd9a2 Replace "--" and "---" with "&mdash;" as appropriate, for better-looking
output.
2004-11-15 06:32:15 +00:00