summaryrefslogtreecommitdiff
path: root/doc/src/sgml/ref/declare.sgml
AgeCommit message (Collapse)Author
2023-01-01In plpgsql, don't preassign portal names to bound cursor variables.Tom Lane
A refcursor variable that is bound to a specific query (by declaring it with "CURSOR FOR") now chooses a portal name in the same way as an unbound, plain refcursor variable. Its string value starts out as NULL, and unless that's overridden by manual assignment, it will be replaced by a unique-within-session portal name during OPEN. The previous behavior was to initialize such variables to contain their own name, resulting in that also being the portal name unless the user overwrote it before OPEN. The trouble with this is that it causes failures due to conflicting portal names if the same cursor variable name is used in different functions. It is pretty non-orthogonal to have bound and unbound refcursor variables behave differently on this point, too, so let's change it. This change can cause compatibility problems for applications that open a bound cursor in a plpgsql function and then use it in the calling code without explicitly passing back the refcursor value (portal name). If the calling code simply assumes that the portal name matches the called function's variable name, it will now fail. That can be fixed by explicitly assigning a string value to the refcursor variable before OPEN, e.g. DECLARE myc CURSOR FOR SELECT ...; BEGIN myc := 'myc'; -- add this OPEN myc; We have no documentation examples showing the troublesome usage pattern, so we can hope it's rare in practice. Patch by me; thanks to Pavel Stehule and Jan Wieck for review. Discussion: https://postgr.es/m/[email protected]
2021-06-08Avoid misbehavior when persisting a non-stable cursor.Tom Lane
PersistHoldablePortal has long assumed that it should store the entire output of the query-to-be-persisted, which requires rewinding and re-reading the output. This is problematic if the query is not stable: we might get different row contents, or even a different number of rows, which'd confuse the cursor state mightily. In the case where the cursor is NO SCROLL, this is very easy to solve: just store the remaining query output, without any rewinding, and tweak the portal's cursor state to match. Aside from removing the semantic problem, this could be significantly more efficient than storing the whole output. If the cursor is scrollable, there's not much we can do, but it was already the case that scrolling a volatile query's result was pretty unsafe. We can just document more clearly that getting correct results from that is not guaranteed. There are already prohibitions in place on using SCROLL with FOR UPDATE/SHARE, which is one way for a SELECT query to have non-stable results. We could imagine prohibiting SCROLL when the query contains volatile functions, but that would be expensive to enforce. Moreover, it could break applications that work just fine, if they have functions that are in fact stable but the user neglected to mark them so. So settle for documenting the hazard. While this problem has existed in some guise for a long time, it got a lot worse in v11, which introduced the possibility of persisting plpgsql cursors (perhaps implicit ones) even when they violate the rules for what can be marked WITH HOLD. Hence, I've chosen to back-patch to v11 but not further. Per bug #17050 from Алексей Булгаков. Discussion: https://postgr.es/m/[email protected]
2021-04-09Fix typos and grammar in documentation and code commentsMichael Paquier
Comment fixes are applied on HEAD, and documentation improvements are applied on back-branches where needed. Author: Justin Pryzby Discussion: https://postgr.es/m/[email protected] Backpatch-through: 9.6
2021-04-07Fix use of cursor sensitivity terminologyPeter Eisentraut
Documentation and comments in code and tests have been using the terms sensitive/insensitive cursor incorrectly relative to the SQL standard. (Cursor sensitivity is only relevant for changes made in the same transaction as the cursor, not for concurrent changes in other sessions.) Moreover, some of the behavior of PostgreSQL is incorrect according to the SQL standard, confusing the issue further. (WHERE CURRENT OF changes are not visible in insensitive cursors, but they should be.) This change corrects the terminology and removes the claim that sensitive cursors are supported. It also adds a test case that checks the insensitive behavior in a "correct" way, using a change command not using WHERE CURRENT OF. Finally, it adds the ASENSITIVE cursor option to select the default asensitive behavior, per SQL standard. There are no changes to cursor behavior in this patch. Discussion: https://www.postgresql.org/message-id/flat/96ee8b30-9889-9e1b-b053-90e10c050e85%40enterprisedb.com
2020-10-03Improve <xref> vs. <command> formatting in the documentationPeter Eisentraut
SQL commands are generally marked up as <command>, except when a link to a reference page is used using <xref>. But the latter doesn't create monospace markup, so this looks strange especially when a paragraph contains a mix of links and non-links. We considered putting <command> in the <refentrytitle> on the target side, but that creates some formatting side effects elsewhere. Generally, it seems safer to solve this on the link source side. We can't put the <xref> inside the <command>; the DTD doesn't allow this. DocBook 5 would allow the <command> to have the linkend attribute itself, but we are not there yet. So to solve this for now, convert the <xref>s to <link> plus <command>. This gives the correct look and also gives some more flexibility what we can put into the link text (e.g., subcommands or other clauses). In the future, these could then be converted to DocBook 5 style. I haven't converted absolutely all xrefs to SQL command reference pages, only those where we care about the appearance of the link text or where it was otherwise appropriate to make the appearance match a bit better. Also in some cases, the links where repetitive, so in those cases the links where just removed and replaced by a plain <command>. In cases where we just want the link and don't specifically care about the generated link text (typically phrased "for further information see <xref ...>") the xref is kept. Reported-by: Dagfinn Ilmari Mannsåker <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
2020-05-11Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.Tom Lane
Use xreflabel attributes instead of endterm attributes to control the appearance of links to subsections of SQL command reference pages. This is simpler, it matches what we do elsewhere (e.g. for GUC variables), and it doesn't draw "Unresolved ID reference" warnings from the PDF toolchain. Fix some places where the text was absolutely dependent on an <xref> rendering exactly so, by using a <link> around the required text instead. At least one of those spots had already been turned into bad grammar by subsequent changes, and the whole idea is just too fragile for my taste. <xref> does NOT have fixed output, don't write as if it does. Consistently include a page-level link in cross-man-page references, because otherwise they are useless/nonsensical in man-page output. Likewise, be consistent about mentioning "below" or "above" in same-page references; we were doing that in about 90% of the cases, but now it's 100%. Also get rid of another nonfunctional-in-PDF idea, of making cross-references to functions by sticking ID tags on <row> constructs. We can put the IDs on <indexterm>s instead --- which is probably not any more sensible in abstract terms, but it works where the other doesn't. (There is talk of attaching cross-reference IDs to most or all of the docs' function descriptions, but for now I just fixed the two that exist.) Discussion: https://postgr.es/m/[email protected]
2018-05-28doc: adjust DECLARE docs to mention FOR UPDATE behaviorBruce Momjian
Reported-by: Peter Eisentraut Discussion: https://postgr.es/m/[email protected] Author: Peter Eisentraut, Tom Lane, me Backpatch-through: 9.3
2017-11-23Convert documentation to DocBook XMLPeter Eisentraut
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-10-20Convert SGML IDs to lower casePeter Eisentraut
IDs in SGML are case insensitive, and we have accumulated a mix of upper and lower case IDs, including different variants of the same ID. In XML, these will be case sensitive, so we need to fix up those differences. Going to all lower case seems most straightforward, and the current build process already makes all anchors and lower case anyway during the SGML->XML conversion, so this doesn't create any difference in the output right now. A future XML-only build process would, however, maintain any mixed case ID spellings in the output, so that is another reason to clean this up beforehand. Author: Alexander Lakhin <[email protected]>
2017-10-17Don't use SGML empty tagsPeter Eisentraut
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
2014-02-24doc: Improve DocBook XML validityPeter Eisentraut
DocBook XML is superficially compatible with DocBook SGML but has a slightly stricter DTD that we have been violating in a few cases. Although XSLT doesn't care whether the document is valid, the style sheets don't necessarily process invalid documents correctly, so we need to work toward fixing this. This first commit moves the indexterms in refentry elements to an allowed position. It has no impact on the output.
2011-08-07Fix a whitespace issue with the man pagesPeter Eisentraut
There is what may actually be a mistake in our markup. The problem is in a situation like <para> <command>FOO</command> is ... there is strictly speaking a line break before "FOO". In the HTML output, this does not appear to be a problem, but in the man page output, this shows up, so you get double blank lines at odd places. So far, we have attempted to work around this with an XSL hack, but that causes other problems, such as creating run-ins in places like <acronym>SQL</acronym> <command>COPY</command> So fix the problem properly by removing the extra whitespace. I only fixed the problems that affect the man page output, not all the places.
2010-09-20Remove cvs keywords from all files.Magnus Hagander
2010-04-03Remove unnecessary xref endterm attributes and title idsPeter Eisentraut
The endterm attribute is mainly useful when the toolchain does not support automatic link target text generation for a particular situation. In the past, this was required by the man page tools for all reference page links, but that is no longer the case, and it now actually gets in the way of proper automatic link text generation. The only remaining use cases are currently xrefs to refsects.
2009-06-10Add a warning about possible strange behavior of volatile functionsTom Lane
in cursors. This has always been the case, but given the lack of user complaints about it, I'm not going to bother back-patching this.
2009-04-10Add cross-references from the DECLARE and FETCH reference pages toTom Lane
the plpgsql documentation about cursors. Per a suggestion from Matthew Wakeling.
2008-11-16Modify UPDATE/DELETE WHERE CURRENT OF to use the FOR UPDATE infrastructure toTom Lane
locate the target row, if the cursor was declared with FOR UPDATE or FOR SHARE. This approach is more flexible and reliable than digging through the plan tree; for instance it can cope with join cursors. But we still provide the old code for use with non-FOR-UPDATE cursors. Per gripe from Robert Haas.
2008-11-14Set SQL man pages to be section 7 by default, and only transform them toPeter Eisentraut
another section if required by the platform (instead of the old way of building them in section "l" and always transforming them to the platform-specific section). This speeds up the installation on common platforms, and it avoids some funny business with the man page tools and build process.
2008-11-04Disallow LOCK TABLE outside a transaction block (or function), since this caseTom Lane
almost certainly represents user error. Per a gripe from Sebastian Böhm and subsequent discussion.
2007-10-24Disallow scrolling of FOR UPDATE/FOR SHARE cursors, so as to avoid problemsTom Lane
in corner cases such as re-fetching a just-deleted row. We may be able to relax this someday, but let's find out how many people really care before we invest a lot of work in it. Per report from Heikki and subsequent discussion. While in the neighborhood, make the combination of INSENSITIVE and FOR UPDATE throw an error, since they are semantically incompatible. (Up to now we've accepted but just ignored the INSENSITIVE option of DECLARE CURSOR.)
2007-06-11Support UPDATE/DELETE WHERE CURRENT OF cursor_name, per SQL standard.Tom Lane
Along the way, allow FOR UPDATE in non-WITH-HOLD cursors; there may once have been a reason to disallow that, but it seems to work now, and it's really rather necessary if you want to select a row via a cursor and then update it in a concurrent-safe fashion. Original patch by Arul Shaji, rather heavily editorialized by Tom Lane.
2007-01-31Update reference documentation on may/can/might:Bruce Momjian
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".
2006-09-18Documentation for VALUES lists. Joe Conway and Tom LaneTom Lane
2006-09-16Remove emacs info from footer of SGML files.Bruce Momjian
2006-02-26Minor SGML work: add some more hyperlinks, where appropriate.Neil Conway
2006-02-12Fix broken markup.Tom Lane
2006-02-12> Actually, if you submit a patch that says either "SCROLL is theBruce Momjian
default" > or "NO SCROLL is the default", it will be rejected as incorrect. The > reason is that the default behavior is different from either of these, > as is explained in the NOTES section. Ok, so *that's* where the bit about the query plan being simple enough. Based on that, ISTM that it should be premissable for us to decide that a cursor requiring a sort isn't "simple enough" to support SCROLL. In any case, here's a patch that makes the non-standard behavior easier for people to find. Jim C. Nasby
2006-01-18Add a new system view, pg_cursors, that displays the currently availableNeil Conway
cursors. Patch from Joachim Wieland, review and ediorialization by Neil Conway. The view lists cursors defined by DECLARE CURSOR, using SPI, or via the Bind message of the frontend/backend protocol. This means the view does not list the unnamed portal or the portal created to implement EXECUTE. Because we do list SPI portals, there might be more rows in this view than you might expect if you are using SPI implicitly (e.g. via a procedural language). Per recent discussion on -hackers, the query string included in the view for cursors defined by DECLARE CURSOR is based on debug_query_string. That means it is not accurate if multiple queries separated by semicolons are submitted as one query string. However, there doesn't seem a trivial fix for that: debug_query_string is better than nothing. I also changed SPI_cursor_open() to include the source text for the portal it creates: AFAICS there is no reason not to do this. Update the documentation and regression tests, bump the catversion.
2005-01-04More minor updates and copy-editing.Tom Lane
2004-11-15Replace "--" and "---" with "&mdash;" as appropriate, for better-lookingNeil Conway
output.
2004-06-17The attached patch adds some index entries pointing to the cursorBruce Momjian
reference pages. Please apply. Alvaro Herrera
2003-11-29$Header: -> $PostgreSQL Changes ...PostgreSQL Daemon
2003-09-22Make the SQL command synopses appear less random.Peter Eisentraut
2003-09-12More cleanup of Diagnostics sections.Tom Lane
2003-09-11This patch fixes a few missed GUC variables that were still upper case,Bruce Momjian
makes a few more small improvements to runtime.sgml, and makes some SGML conventions more consistent. Neil Conway
2003-08-31Add/edit index entries.Peter Eisentraut
2003-08-24Change warnings for non-existing or pre-existing cursors to errors.Peter Eisentraut
2003-05-04Last round of reference page editing.Peter Eisentraut
2003-04-29Code review for holdable-cursors patch. Fix error recovery, memoryTom Lane
context sloppiness, some other things. Includes Neil's mopup patch of 22-Apr.
2003-04-06Fix markup.Peter Eisentraut
2003-03-27This patch implements holdable cursors, following the proposalBruce Momjian
(materialization into a tuple store) discussed on pgsql-hackers earlier. I've updated the documentation and the regression tests. Notes on the implementation: - I needed to change the tuple store API slightly -- it assumes that it won't be used to hold data across transaction boundaries, so the temp files that it uses for on-disk storage are automatically reclaimed at end-of-transaction. I added a flag to tuplestore_begin_heap() to control this behavior. Is changing the tuple store API in this fashion OK? - in order to store executor results in a tuple store, I added a new CommandDest. This works well for the most part, with one exception: the current DestFunction API doesn't provide enough information to allow the Executor to store results into an arbitrary tuple store (where the particular tuple store to use is chosen by the call site of ExecutorRun). To workaround this, I've temporarily hacked up a solution that works, but is not ideal: since the receiveTuple DestFunction is passed the portal name, we can use that to lookup the Portal data structure for the cursor and then use that to get at the tuple store the Portal is using. This unnecessarily ties the Portal code with the tupleReceiver code, but it works... The proper fix for this is probably to change the DestFunction API -- Tom suggested passing the full QueryDesc to the receiveTuple function. In that case, callers of ExecutorRun could "subclass" QueryDesc to add any additional fields that their particular CommandDest needed to get access to. This approach would work, but I'd like to think about it for a little bit longer before deciding which route to go. In the mean time, the code works fine, so I don't think a fix is urgent. - (semi-related) I added a NO SCROLL keyword to DECLARE CURSOR, and adjusted the behavior of SCROLL in accordance with the discussion on -hackers. - (unrelated) Cleaned up some SGML markup in sql.sgml, copy.sgml Neil Conway
2003-03-21Remove mention of transactions for insensitive cursors.Bruce Momjian
2003-03-10Restructure parsetree representation of DECLARE CURSOR: now it's aTom Lane
utility statement (DeclareCursorStmt) with a SELECT query dangling from it, rather than a SELECT query with a few unusual fields in it. Add code to determine whether a planned query can safely be run backwards. If DECLARE CURSOR specifies SCROLL, ensure that the plan can be run backwards by adding a Materialize plan node if it can't. Without SCROLL, you get an error if you try to fetch backwards from a cursor that can't handle it. (There is still some discussion about what the exact behavior should be, but this is necessary infrastructure in any case.) Along the way, make EXPLAIN DECLARE CURSOR work.
2002-05-18Revise command completion tags as per hackers message on 20 March.Peter Eisentraut
2002-04-21Augment the date/time examples in the User's Guide to reflect the newerThomas G. Lockhart
capabilities of specifying time zones as intervals per SQL9x. Put refentrytitle contents on the same line as the tag. Otherwise, leading whitespace is propagated into the product, which (at least) messes up the ToC layout. Remove (some) docinfo tags containing dates. Best to omit if the dates are not accurate; maybe use CVS dates instead or leave them out.
2002-03-06Update reference pages for new INFO, NOTICE, WARNING elog() levels.Bruce Momjian
2001-12-08Use PostgreSQL consistantly throughout docs. Before, usage was split evenlyThomas G. Lockhart
between Postgres and PostgreSQL.
2001-09-13Replace ASCII-quotes with proper markup.Peter Eisentraut
2001-09-03Put some kind of grammatical uniformity in the <refpurpose> lines.Peter Eisentraut
2001-02-15Update obsolete wording of error message.Tom Lane