Skip to content
Snippets Groups Projects
  1. May 02, 2012
  2. Apr 26, 2012
    • Peter Eisentraut's avatar
      PL/Python: Accept strings in functions returning composite types · ba3e4157
      Peter Eisentraut authored
      Before 9.1, PL/Python functions returning composite types could return
      a string and it would be parsed using record_in.  The 9.1 changes made
      PL/Python only expect dictionaries, tuples, or objects supporting
      getattr as output of composite functions, resulting in a regression
      and a confusing error message, as the strings were interpreted as
      sequences and the code for transforming lists to database tuples was
      used.  Fix this by treating strings separately as before, before
      checking for the other types.
      
      The reason why it's important to support string to database tuple
      conversion is that trigger functions on tables with composite columns
      get the composite row passed in as a string (from record_out).
      Without supporting converting this back using record_in, this makes it
      impossible to implement pass-through behavior for these columns, as
      PL/Python no longer accepts strings for composite values.
      
      A better solution would be to fix the code that transforms composite
      inputs into Python objects to produce dictionaries that would then be
      correctly interpreted by the Python->PostgreSQL counterpart code.  But
      that would be too invasive to backpatch to 9.1, and it is too late in
      the 9.2 cycle to attempt it.  It should be revisited in the future,
      though.
      
      Reported as bug #6559 by Kirill Simonov.
      
      Jan Urbański
      ba3e4157
  3. Apr 25, 2012
  4. Apr 24, 2012
  5. Apr 16, 2012
  6. Apr 15, 2012
  7. Apr 05, 2012
    • Tom Lane's avatar
      Fix plpgsql named-cursor-parameter feature for variable name conflicts. · 05dbd4a7
      Tom Lane authored
      The parser got confused if a cursor parameter had the same name as
      a plpgsql variable.  Reported and diagnosed by Yeb Havinga, though
      this isn't exactly his proposed fix.
      
      Also, some mostly-but-not-entirely-cosmetic adjustments to the original
      named-cursor-parameter patch, for code readability and better error
      diagnostics.
      05dbd4a7
  8. Mar 22, 2012
    • Tom Lane's avatar
      Fix GET DIAGNOSTICS for case of assignment to function's first variable. · 88a4cb30
      Tom Lane authored
      An incorrect and entirely unnecessary "safety check" in exec_stmt_getdiag()
      caused the code to treat an assignment to a variable with dno zero as a
      no-op.  Unfortunately, that's a perfectly valid dno.  This has been broken
      since GET DIAGNOSTICS was invented.  It's not terribly surprising that the
      bug went unnoticed for so long, since in most cases you probably wouldn't
      use the function's first-created variable (normally its first parameter)
      as a GET DIAGNOSTICS target.  Nonetheless, it's broken.  Per bug #6551
      from Adam Buraczewski.
      88a4cb30
  9. Mar 20, 2012
    • Tom Lane's avatar
      Restructure SELECT INTO's parsetree representation into CreateTableAsStmt. · 9dbf2b7d
      Tom Lane authored
      Making this operation look like a utility statement seems generally a good
      idea, and particularly so in light of the desire to provide command
      triggers for utility statements.  The original choice of representing it as
      SELECT with an IntoClause appendage had metastasized into rather a lot of
      places, unfortunately, so that this patch is a great deal more complicated
      than one might at first expect.
      
      In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS
      subcommands required restructuring some EXPLAIN-related APIs.  Add-on code
      that calls ExplainOnePlan or ExplainOneUtility, or uses
      ExplainOneQuery_hook, will need adjustment.
      
      Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO,
      which formerly were accepted though undocumented, are no longer accepted.
      The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE.
      The CREATE RULE case doesn't seem to have much real-world use (since the
      rule would work only once before failing with "table already exists"),
      so we'll not bother with that one.
      
      Both SELECT INTO and CREATE TABLE AS still return a command tag of
      "SELECT nnnn".  There was some discussion of returning "CREATE TABLE nnnn",
      but for the moment backwards compatibility wins the day.
      
      Andres Freund and Tom Lane
      9dbf2b7d
  10. Mar 19, 2012
    • Alvaro Herrera's avatar
      plperl: Package-qualify _TD · 814e08e8
      Alvaro Herrera authored
      Failing to do so causes trigger invocation to fail when they are nested
      within a function invocation that changes the current package.
      
      Backpatch to 9.1; previous releases used a different method to obtain
      _TD.  Per bug report from Mark Murawski (bug #6511)
      
      Author: Alex Hunsaker
      814e08e8
  11. Mar 13, 2012
    • Tom Lane's avatar
      Patch some corner-case bugs in pl/python. · 5cd72c7a
      Tom Lane authored
      Dave Malcolm of Red Hat is working on a static code analysis tool for
      Python-related C code.  It reported a number of problems in plpython,
      most of which were failures to check for NULL results from object-creation
      functions, so would only be an issue in very-low-memory situations.
      
      Patch in HEAD and 9.1.  We could go further back but it's not clear that
      these issues are important enough to justify the work.
      
      Jan Urbański
      5cd72c7a
    • Tom Lane's avatar
      Fix minor memory leak in PLy_typeinfo_dealloc(). · a14fa846
      Tom Lane authored
      We forgot to free the per-attribute array element descriptors.
      
      Jan Urbański
      a14fa846
    • Tom Lane's avatar
      Create a stack of pl/python "execution contexts". · ed75380b
      Tom Lane authored
      This replaces the former global variable PLy_curr_procedure, and provides
      a place to stash per-call-level information.  In particular we create a
      per-call-level scratch memory context.
      
      For the moment, the scratch context is just used to avoid leaking memory
      from datatype output function calls in PLyDict_FromTuple.  There probably
      will be more use-cases in future.
      
      Although this is a fix for a pre-existing memory leakage bug, it seems
      sufficiently invasive to not want to back-patch; it feels better as part
      of the major rearrangement of plpython code that we've already done as
      part of 9.2.
      
      Jan Urbański
      ed75380b
  12. Feb 12, 2012
    • Tom Lane's avatar
      Fix I/O-conversion-related memory leaks in plpgsql. · 58a9596e
      Tom Lane authored
      Datatype I/O functions are allowed to leak memory in CurrentMemoryContext,
      since they are generally called in short-lived contexts.  However, plpgsql
      calls such functions for purposes of type conversion, and was calling them
      in its procedure context.  Therefore, any leaked memory would not be
      recovered until the end of the plpgsql function.  If such a conversion
      was done within a loop, quite a bit of memory could get consumed.  Fix by
      calling such functions in the transient "eval_econtext", and adjust other
      logic to match.  Back-patch to all supported versions.
      
      Andres Freund, Jan Urbański, Tom Lane
      58a9596e
  13. Feb 01, 2012
    • Tom Lane's avatar
      Code review for plpgsql fn_signature patch. · bef47331
      Tom Lane authored
      Don't quote the output of format_procedure(); it's already quoted quite
      enough.  Remove the fn_name field, which was now just dead weight.  Fix
      remaining expected-output files.
      bef47331
  14. Jan 31, 2012
  15. Jan 30, 2012
    • Peter Eisentraut's avatar
      PL/Python: Add result metadata functions · ee7fa66b
      Peter Eisentraut authored
      Add result object functions .colnames, .coltypes, .coltypmods to
      obtain information about the result column names and types, which was
      previously not possible in the PL/Python SPI interface.
      
      reviewed by Abhijit Menon-Sen
      ee7fa66b
  16. Jan 15, 2012
  17. Jan 10, 2012
  18. Jan 05, 2012
    • Andrew Dunstan's avatar
      Fix breakage from earlier plperl fix. · bd0e74a9
      Andrew Dunstan authored
      Apparently the perl garbage collector was a bit too eager, so here
      we control when the new SV is garbage collected.
      bd0e74a9
    • Andrew Dunstan's avatar
      Work around perl bug in SvPVutf8(). · 2abefd9a
      Andrew Dunstan authored
      Certain things like typeglobs or readonly things like $^V cause
      perl's SvPVutf8() to die nastily and crash the backend. To avoid
      that bug we make a copy of the object, which will subsequently be
      garbage collected.
      
      Back patched to 9.1 where we first started using SvPVutf8().
      
      Per -hackers discussion. Original problem reported by David Wheeler.
      2abefd9a
  19. Jan 02, 2012
  20. Dec 29, 2011
  21. Dec 27, 2011
  22. Dec 18, 2011
    • Peter Eisentraut's avatar
    • Peter Eisentraut's avatar
      Split plpython.c into smaller pieces · 147c2482
      Peter Eisentraut authored
      This moves the code around from one huge file into hopefully logical
      and more manageable modules.  For the most part, the code itself was
      not touched, except: PLy_function_handler and PLy_trigger_handler were
      renamed to PLy_exec_function and PLy_exec_trigger, because they were
      not actually handlers in the PL handler sense, and it makes the naming
      more similar to the way PL/pgSQL is organized.  The initialization of
      the procedure caches was separated into a new function
      init_procedure_caches to keep the hash tables private to
      plpy_procedures.c.
      
      Jan Urbański and Peter Eisentraut
      147c2482
  23. Dec 15, 2011
  24. Dec 14, 2011
  25. Dec 05, 2011
    • Peter Eisentraut's avatar
      plpython: Add SPI cursor support · 89e850e6
      Peter Eisentraut authored
      Add a function plpy.cursor that is similar to plpy.execute but uses an
      SPI cursor to avoid fetching the entire result set into memory.
      
      Jan Urbański, reviewed by Steve Singer
      89e850e6
  26. Nov 30, 2011
    • Robert Haas's avatar
      Improve table locking behavior in the face of current DDL. · 2ad36c4e
      Robert Haas authored
      In the previous coding, callers were faced with an awkward choice:
      look up the name, do permissions checks, and then lock the table; or
      look up the name, lock the table, and then do permissions checks.
      The first choice was wrong because the results of the name lookup
      and permissions checks might be out-of-date by the time the table
      lock was acquired, while the second allowed a user with no privileges
      to interfere with access to a table by users who do have privileges
      (e.g. if a malicious backend queues up for an AccessExclusiveLock on
      a table on which AccessShareLock is already held, further attempts
      to access the table will be blocked until the AccessExclusiveLock
      is obtained and the malicious backend's transaction rolls back).
      
      To fix, allow callers of RangeVarGetRelid() to pass a callback which
      gets executed after performing the name lookup but before acquiring
      the relation lock.  If the name lookup is retried (because
      invalidation messages are received), the callback will be re-executed
      as well, so we get the best of both worlds.  RangeVarGetRelid() is
      renamed to RangeVarGetRelidExtended(); callers not wishing to supply
      a callback can continue to invoke it as RangeVarGetRelid(), which is
      now a macro.  Since the only one caller that uses nowait = true now
      passes a callback anyway, the RangeVarGetRelid() macro defaults nowait
      as well.  The callback can also be used for supplemental locking - for
      example, REINDEX INDEX needs to acquire the table lock before the index
      lock to reduce deadlock possibilities.
      
      There's a lot more work to be done here to fix all the cases where this
      can be a problem, but this commit provides the general infrastructure
      and fixes the following specific cases: REINDEX INDEX, REINDEX TABLE,
      LOCK TABLE, and and DROP TABLE/INDEX/SEQUENCE/VIEW/FOREIGN TABLE.
      
      Per discussion with Noah Misch and Alvaro Herrera.
      2ad36c4e
  27. Nov 29, 2011
    • Peter Eisentraut's avatar
      plpython: Fix sed expression in python3 build · 04e5cb62
      Peter Eisentraut authored
      The old expression sed 's,$(srcdir),python3,' would normally resolve
      as sed 's,.,python3,', which is not really what we wanted.  While it
      doesn't actually break anything right now, it's still wrong, so put in
      a bit more work to make it more robust.
      04e5cb62
  28. Nov 27, 2011
  29. Nov 26, 2011
  30. Nov 24, 2011
  31. Nov 21, 2011
  32. Nov 13, 2011
    • Tom Lane's avatar
      In plpgsql, allow foreign tables to define row types. · 02d88efe
      Tom Lane authored
      This seems to have been just an oversight in previous foreign-table work.
      A quick grep didn't turn up any other places where RELKIND_FOREIGN_TABLE
      was obviously omitted.
      
      One change noted by Alexander Soudakov, the other by me.
      Back-patch to 9.1.
      02d88efe
Loading