Skip to content
Snippets Groups Projects
  1. Jan 31, 2018
  2. Jan 24, 2018
  3. Sep 17, 2017
  4. Sep 16, 2017
    • Tom Lane's avatar
      Fix SQL-spec incompatibilities in new transition table feature. · 54d4d0ff
      Tom Lane authored
      The standard says that all changes of the same kind (insert, update, or
      delete) caused in one table by a single SQL statement should be reported
      in a single transition table; and by that, they mean to include foreign key
      enforcement actions cascading from the statement's direct effects.  It's
      also reasonable to conclude that if the standard had wCTEs, they would say
      that effects of wCTEs applying to the same table as each other or the outer
      statement should be merged into one transition table.  We weren't doing it
      like that.
      
      Hence, arrange to merge tuples from multiple update actions into a single
      transition table as much as we can.  There is a problem, which is that if
      the firing of FK enforcement triggers and after-row triggers with
      transition tables is interspersed, we might need to report more tuples
      after some triggers have already seen the transition table.  It seems like
      a bad idea for the transition table to be mutable between trigger calls.
      There's no good way around this without a major redesign of the FK logic,
      so for now, resolve it by opening a new transition table each time this
      happens.
      
      Also, ensure that AFTER STATEMENT triggers fire just once per statement,
      or once per transition table when we're forced to make more than one.
      Previous versions of Postgres have allowed each FK enforcement query
      to cause an additional firing of the AFTER STATEMENT triggers for the
      referencing table, but that's certainly not per spec.  (We're still
      doing multiple firings of BEFORE STATEMENT triggers, though; is that
      something worth changing?)
      
      Also, forbid using transition tables with column-specific UPDATE triggers.
      The spec requires such transition tables to show only the tuples for which
      the UPDATE trigger would have fired, which means maintaining multiple
      transition tables or else somehow filtering the contents at readout.
      Maybe someday we'll bother to support that option, but it looks like a
      lot of trouble for a marginal feature.
      
      The transition tables are now managed by the AfterTriggers data structures,
      rather than being directly the responsibility of ModifyTable nodes.  This
      removes a subtransaction-lifespan memory leak introduced by my previous
      band-aid patch 3c435952.
      
      In passing, refactor the AfterTriggers data structures to reduce the
      management overhead for them, by using arrays of structs rather than
      several parallel arrays for per-query-level and per-subtransaction state.
      
      I failed to resist the temptation to do some copy-editing on the SGML
      docs about triggers, above and beyond merely documenting the effects
      of this patch.
      
      Back-patch to v10, because we don't want the semantics of transition
      tables to change post-release.
      
      Patch by me, with help and review from Thomas Munro.
      
      Discussion: https://postgr.es/m/20170909064853.25630.12825@wrigleys.postgresql.org
      54d4d0ff
  5. Jun 28, 2017
  6. Apr 18, 2017
  7. Apr 05, 2017
    • Kevin Grittner's avatar
      Follow-on cleanup for the transition table patch. · 5ebeb579
      Kevin Grittner authored
      Commit 59702716 added transition table support to PL/pgsql so that
      SQL queries in trigger functions could access those transient
      tables.  In order to provide the same level of support for PL/perl,
      PL/python and PL/tcl, refactor the relevant code into a new
      function SPI_register_trigger_data.  Call the new function in the
      trigger handler of all four PLs, and document it as a public SPI
      function so that authors of out-of-tree PLs can do the same.
      
      Also get rid of a second QueryEnvironment object that was
      maintained by PL/pgsql.  That was previously used to deal with
      cursors, but the same approach wasn't appropriate for PLs that are
      less tangled up with core code.  Instead, have SPI_cursor_open
      install the connection's current QueryEnvironment, as already
      happens for SPI_execute_plan.
      
      While in the docs, remove the note that transition tables were only
      supported in C and PL/pgSQL triggers, and correct some ommissions.
      
      Thomas Munro with some work by Kevin Grittner (mostly docs)
      5ebeb579
  8. Apr 01, 2017
  9. Mar 14, 2017
  10. Nov 04, 2016
    • Kevin Grittner's avatar
      Implement syntax for transition tables in AFTER triggers. · 8c48375e
      Kevin Grittner authored
      This is infrastructure for the complete SQL standard feature.  No
      support is included at this point for execution nodes or PLs.  The
      intent is to add that soon.
      
      As this patch leaves things, standard syntax can create tuplestores
      to contain old and/or new versions of rows affected by a statement.
      References to these tuplestores are in the TriggerData structure.
      C triggers can access the tuplestores directly, so they are usable,
      but they cannot yet be referenced within a SQL statement.
      8c48375e
  11. May 08, 2015
    • Andres Freund's avatar
      Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE. · 168d5805
      Andres Freund authored
      The newly added ON CONFLICT clause allows to specify an alternative to
      raising a unique or exclusion constraint violation error when inserting.
      ON CONFLICT refers to constraints that can either be specified using a
      inference clause (by specifying the columns of a unique constraint) or
      by naming a unique or exclusion constraint.  DO NOTHING avoids the
      constraint violation, without touching the pre-existing row.  DO UPDATE
      SET ... [WHERE ...] updates the pre-existing tuple, and has access to
      both the tuple proposed for insertion and the existing tuple; the
      optional WHERE clause can be used to prevent an update from being
      executed.  The UPDATE SET and WHERE clauses have access to the tuple
      proposed for insertion using the "magic" EXCLUDED alias, and to the
      pre-existing tuple using the table name or its alias.
      
      This feature is often referred to as upsert.
      
      This is implemented using a new infrastructure called "speculative
      insertion". It is an optimistic variant of regular insertion that first
      does a pre-check for existing tuples and then attempts an insert.  If a
      violating tuple was inserted concurrently, the speculatively inserted
      tuple is deleted and a new attempt is made.  If the pre-check finds a
      matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
      If the insertion succeeds without detecting a conflict, the tuple is
      deemed inserted.
      
      To handle the possible ambiguity between the excluded alias and a table
      named excluded, and for convenience with long relation names, INSERT
      INTO now can alias its target table.
      
      Bumps catversion as stored rules change.
      
      Author: Peter Geoghegan, with significant contributions from Heikki
          Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
      Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
          Dean Rasheed, Stephen Frost and many others.
      168d5805
  12. Jan 10, 2015
  13. Jun 21, 2014
    • Kevin Grittner's avatar
      Fix documentation template for CREATE TRIGGER. · 734bea8a
      Kevin Grittner authored
      By using curly braces, the template had specified that one of
      "NOT DEFERRABLE", "INITIALLY IMMEDIATE", or "INITIALLY DEFERRED"
      was required on any CREATE TRIGGER statement, which is not
      accurate.  Change to square brackets makes that optional.
      
      Backpatch to 9.1, where the error was introduced.
      734bea8a
  14. Mar 23, 2014
    • Noah Misch's avatar
      Offer triggers on foreign tables. · 7cbe57c3
      Noah Misch authored
      This covers all the SQL-standard trigger types supported for regular
      tables; it does not cover constraint triggers.  The approach for
      acquiring the old row mirrors that for view INSTEAD OF triggers.  For
      AFTER ROW triggers, we spool the foreign tuples to a tuplestore.
      
      This changes the FDW API contract; when deciding which columns to
      populate in the slot returned from data modification callbacks, writable
      FDWs will need to check for AFTER ROW triggers in addition to checking
      for a RETURNING clause.
      
      In support of the feature addition, refactor the TriggerFlags bits and
      the assembly of old tuples in ModifyTable.
      
      Ronan Dunklau, reviewed by KaiGai Kohei; some additional hacking by me.
      7cbe57c3
  15. Feb 24, 2014
    • Peter Eisentraut's avatar
      doc: Improve DocBook XML validity · bb4eefe7
      Peter Eisentraut authored
      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.
      bb4eefe7
  16. Jul 03, 2013
  17. Feb 23, 2013
  18. Jun 22, 2012
  19. Feb 23, 2012
    • Tom Lane's avatar
      Require execute permission on the trigger function for CREATE TRIGGER. · 891e6e7b
      Tom Lane authored
      This check was overlooked when we added function execute permissions to the
      system years ago.  For an ordinary trigger function it's not a big deal,
      since trigger functions execute with the permissions of the table owner,
      so they couldn't do anything the user issuing the CREATE TRIGGER couldn't
      have done anyway.  However, if a trigger function is SECURITY DEFINER,
      that is not the case.  The lack of checking would allow another user to
      install it on his own table and then invoke it with, essentially, forged
      input data; which the trigger function is unlikely to realize, so it might
      do something undesirable, for instance insert false entries in an audit log
      table.
      
      Reported by Dinesh Kumar, patch by Robert Haas
      
      Security: CVE-2012-0866
      891e6e7b
  20. Aug 07, 2011
    • Peter Eisentraut's avatar
      Fix a whitespace issue with the man pages · 6ef24487
      Peter Eisentraut authored
      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.
      6ef24487
  21. Mar 07, 2011
  22. Mar 02, 2011
  23. Nov 09, 2010
  24. Oct 10, 2010
    • Tom Lane's avatar
      Support triggers on views. · 2ec993a7
      Tom Lane authored
      This patch adds the SQL-standard concept of an INSTEAD OF trigger, which
      is fired instead of performing a physical insert/update/delete.  The
      trigger function is passed the entire old and/or new rows of the view,
      and must figure out what to do to the underlying tables to implement
      the update.  So this feature can be used to implement updatable views
      using trigger programming style rather than rule hacking.
      
      In passing, this patch corrects the names of some columns in the
      information_schema.triggers view.  It seems the SQL committee renamed
      them somewhere between SQL:99 and SQL:2003.
      
      Dean Rasheed, reviewed by Bernd Helmle; some additional hacking by me.
      2ec993a7
  25. Sep 20, 2010
  26. Aug 17, 2010
  27. Apr 03, 2010
    • Peter Eisentraut's avatar
      Remove unnecessary xref endterm attributes and title ids · 6dcce398
      Peter Eisentraut authored
      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.
      6dcce398
  28. Nov 20, 2009
    • Tom Lane's avatar
      Add a WHEN clause to CREATE TRIGGER, allowing a boolean expression to be · 7fc0f062
      Tom Lane authored
      checked to determine whether the trigger should be fired.
      
      For BEFORE triggers this is mostly a matter of spec compliance; but for AFTER
      triggers it can provide a noticeable performance improvement, since queuing of
      a deferred trigger event and re-fetching of the row(s) at end of statement can
      be short-circuited if the trigger does not need to be fired.
      
      Takahiro Itagaki, reviewed by KaiGai Kohei.
      7fc0f062
  29. Oct 15, 2009
    • Tom Lane's avatar
      Support SQL-compliant triggers on columns, ie fire only if certain columns · b2734a0d
      Tom Lane authored
      are named in the UPDATE's SET list.
      
      Note: the schema of pg_trigger has not actually changed; we've just started
      to use a column that was there all along.  catversion bumped anyway so that
      this commit is included in the history of potentially interesting changes
      to system catalog contents.
      
      Itagaki Takahiro
      b2734a0d
  30. Sep 19, 2009
  31. Nov 14, 2008
  32. Mar 28, 2008
  33. Feb 01, 2007
    • Bruce Momjian's avatar
      Wording cleanup for error messages. Also change can't -> cannot. · 8b4ff8b6
      Bruce Momjian authored
      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".
      8b4ff8b6
    • Bruce Momjian's avatar
      Update reference documentation on may/can/might: · e81c138e
      Bruce Momjian authored
      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".
      e81c138e
  34. Oct 23, 2006
  35. Sep 16, 2006
  36. Dec 09, 2005
  37. Nov 01, 2005
  38. Jul 14, 2005
  39. Nov 27, 2004
Loading