summaryrefslogtreecommitdiff
path: root/src/pl/plpgsql
Commit message (Collapse)AuthorAgeFilesLines
* Fix up text concatenation so that it accepts all the reasonable cases thatTom Lane2007-06-061-2/+3
| | | | | | | | were accepted by prior Postgres releases. This takes care of the loose end left by the preceding patch to downgrade implicit casts-to-text. To avoid breaking desirable behavior for array concatenation, introduce a new polymorphic pseudo-type "anynonarray" --- the added concatenation operators are actually text || anynonarray and anynonarray || text.
* Downgrade implicit casts to text to be assignment-only, except for the onesTom Lane2007-06-051-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | from the other string-category types; this eliminates a lot of surprising interpretations that the parser could formerly make when there was no directly applicable operator. Create a general mechanism that supports casts to and from the standard string types (text,varchar,bpchar) for *every* datatype, by invoking the datatype's I/O functions. These new casts are assignment-only in the to-string direction, explicit-only in the other, and therefore should create no surprising behavior. Remove a bunch of thereby-obsoleted datatype-specific casting functions. The "general mechanism" is a new expression node type CoerceViaIO that can actually convert between *any* two datatypes if their external text representations are compatible. This is more general than needed for the immediate feature, but might be useful in plpgsql or other places in future. This commit does nothing about the issue that applying the concatenation operator || to non-text types will now fail, often with strange error messages due to misinterpreting the operator as array concatenation. Since it often (not always) worked before, we should either make it succeed or at least give a more user-friendly error; but details are still under debate. Peter Eisentraut and Tom Lane
* Support for MOVE in PL/PgSQL. Initial patch from Magnus, some improvementsNeil Conway2007-04-295-46/+121
| | | | by Pavel Stehule, and reviewed by Neil Conway.
* Add support for IN as alternative to FROM in PL/PgSQL's FETCH statement,Neil Conway2007-04-281-6/+19
| | | | | for consistency with the backend's FETCH command. Patch from Pavel Stehule, reviewed by Neil Conway.
* Fix plpgsql to avoid reference to already-freed memory when returning aTom Lane2007-04-191-1/+20
| | | | | | | pass-by-reference data type and the RETURN statement is within an EXCEPTION block. Bug introduced by my fix of 2007-01-28 to use per-subtransaction ExprContexts/EStates; since that wasn't back-patched into older branches, only 8.2 and HEAD are affected. Per report from Gary Winslow.
* Support scrollable cursors (ie, 'direction' clause in FETCH) in plpgsql.Tom Lane2007-04-164-67/+183
| | | | Pavel Stehule, reworked a bit by Tom.
* Support enum data types. Along the way, use macros for the values ofTom Lane2007-04-023-25/+23
| | | | | pg_type.typtype whereever practical. Tom Dunstan, with some kibitzing from Tom Lane.
* Fix array coercion expressions to ensure that the correct volatility isTom Lane2007-03-271-1/+4
| | | | | | | | | seen by code inspecting the expression. The best way to do this seems to be to drop the original representation as a function invocation, and instead make a special expression node type that represents applying the element-type coercion function to each array element. In this way the element function is exposed and will be checked for volatility. Per report from Guillaume Smet.
* Remove the prohibition on executing cursor commands through SPI_execute.Tom Lane2007-03-251-11/+1
| | | | | | | | | Vadim had included this restriction in the original design of the SPI code, but I'm darned if I can see a reason for it. I left the macro definition of SPI_ERROR_CURSOR in place, so as not to needlessly break any SPI callers that are checking for it, but that code will never actually be returned anymore.
* Code cleanup for function prototypes: change two K&R-style prototypesNeil Conway2007-03-181-2/+2
| | | | to ANSI-style, and change "()" -> "(void)". Patch from Stefan Huehner.
* Make use of plancache module for SPI plans. In particular, since plpgsqlTom Lane2007-03-152-35/+91
| | | | | | | | | | | | uses SPI plans, this finally fixes the ancient gotcha that you can't drop and recreate a temp table used by a plpgsql function. Along the way, clean up SPI's API a little bit by declaring SPI plan pointers as "SPIPlanPtr" instead of "void *". This is cosmetic but helps to forestall simple programming mistakes. (I have changed some but not all of the callers to match; there are still some "void *"'s in contrib and the PL's. This is intentional so that we can see if anyone's compiler complains about it.)
* Remove the Query structure from the executor's API. This allows us to stopTom Lane2007-02-201-12/+17
| | | | | | | | | | | | | | | storing mostly-redundant Query trees in prepared statements, portals, etc. To replace Query, a new node type called PlannedStmt is inserted by the planner at the top of a completed plan tree; this carries just the fields of Query that are still needed at runtime. The statement lists kept in portals etc. now consist of intermixed PlannedStmt and bare utility-statement nodes --- no Query. This incidentally allows us to remove some fields from Query and Plan nodes that shouldn't have been there in the first place. Still to do: simplify the execution-time range table; at the moment the range table passed to the executor still contains Query trees for subqueries. initdb forced due to change of stored rules.
* Improve plpgsql's error message when a datatype declaration is omitted.Tom Lane2007-02-191-28/+16
| | | | Per example from Jeff Ross.
* Replace useless uses of := by = in makefiles.Peter Eisentraut2007-02-091-2/+2
|
* Combine cmin and cmax fields of HeapTupleHeaders into a single field, byTom Lane2007-02-092-5/+5
| | | | | | | | | | keeping private state in each backend that has inserted and deleted the same tuple during its current top-level transaction. This is sufficient since there is no need to be able to determine the cmin/cmax from any other transaction. This gets us back down to 23-byte headers, removing a penalty paid in 8.0 to support subtransactions. Patch by Heikki Linnakangas, with minor revisions by moi, following a design hashed out awhile back on the pghackers list.
* Fix an ancient logic error in plpgsql's exec_stmt_block: it thought it couldTom Lane2007-02-081-32/+40
| | | | | | | | | | | | | | | | | | | get away with not (re)initializing a local variable if the variable is marked "isconst" and not "isnull". Unfortunately it makes this decision after having already freed the old value, meaning that something like for i in 1..10 loop declare c constant text := 'hi there'; leads to subsequent accesses to freed memory, and hence probably crashes. (In particular, this is why Asif Ali Rehman's bug leads to crash and not just an unexpectedly-NULL value for SQLERRM: SQLERRM is marked CONSTANT and so triggers this error.) The whole thing seems wrong on its face anyway: CONSTANT means that you can't change the variable inside the block, not that the initializer expression is guaranteed not to change value across successive block entries. Hence, remove the "optimization" instead of trying to fix it.
* Rearrange use of plpgsql_add_initdatums() so that only the parsing of aTom Lane2007-02-082-17/+17
| | | | | | | | | | | | | | DECLARE section needs to know about it. Formerly, everyplace besides DECLARE that created variables needed to do "plpgsql_add_initdatums(NULL)" to prevent those variables from being sucked up as part of a subsequent DECLARE block. This is obviously error-prone, and in fact the SQLSTATE/SQLERRM patch had failed to do it for those two variables, leading to the bug recently exhibited by Asif Ali Rehman: a DECLARE within an exception handler tried to reinitialize SQLERRM. Although the SQLSTATE/SQLERRM patch isn't in any pre-8.1 branches, and so I can't point to a demonstrable failure there, it seems wise to back-patch this into the older branches anyway, just to keep the logic similar to HEAD.
* Fix plpgsql so that when a local variable has no initial-value expression,Tom Lane2007-02-011-1/+20
| | | | | an error will be thrown correctly if the variable is of a NOT NULL domain. Report and almost-correct fix from Sergiy Vyshnevetskiy (bug #2948).
* Wording cleanup for error messages. Also change can't -> cannot.Bruce Momjian2007-02-012-4/+4
| | | | | | | | | | | | | | 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".
* Repair oversights in the mechanism used to store compiled plpgsql functions.Tom Lane2007-01-303-31/+115
| | | | | | | | | | | | | The original coding failed (tried to access deallocated memory) if there were two active call sites (fn_extra pointers) for the same function and the function definition was updated. Also, if an update of a recursive function was detected upon nested entry to the function, the existing compiled version was summarily deallocated, resulting in crash upon return to the outer instance. Problem observed while studying a bug report from Sergiy Vyshnevetskiy. Bug does not exist before 8.1 since older versions just leaked the memory of obsoleted compiled functions, rather than trying to reclaim it.
* Add SPI_push/SPI_pop calls so that datatype input and output functions calledTom Lane2007-01-301-2/+28
| | | | | | | | | by plpgsql can themselves use SPI --- possibly indirectly, as in the case of domain_in() invoking plpgsql functions in a domain check constraint. Per bug #2945 from Sergiy Vyshnevetskiy. Somewhat arbitrarily, I've chosen to back-patch this as far as 8.0. Given the lack of prior complaints, it doesn't seem critical for 7.x.
* Make some small improvements in the accuracy of plpgsql's error locationTom Lane2007-01-282-37/+80
| | | | | | reports; inspired by the misleading CONTEXT lines shown in recent bug report from Stefan Kaltenbrunner. Also, allow statement-type names shown in these messages to be translated.
* Fix up plpgsql's "simple expression" evaluation mechanism so that it behavesTom Lane2007-01-283-46/+156
| | | | | | | | | | | | | | safely in the presence of subtransactions. To ensure that any ExprContext shutdown callbacks are called at the right times, we have to have a separate EState for each level of subtransaction. Per "TupleDesc reference leak" bug report from Stefan Kaltenbrunner. Although I'm convinced the code is wrong as far back as 8.0, it doesn't seem that there are any ways for the problem to really manifest before 8.2: AFAICS, 8.0 and 8.1 only use the ExprContextCallback mechanism to handle set-returning functions, which cannot usefully be executed in a "simple expression" anyway. Hence, no backpatch before 8.2 --- the risk of unforeseen breakage seems to outweigh the chance of fixing something.
* Enable another five tuple status bits by using the high bits of theBruce Momjian2007-01-091-3/+3
| | | | | | nattr field, and rename the field. Heikki Linnakangas
* Update CVS HEAD for 2007 copyright. Back branches are typically notBruce Momjian2007-01-058-16/+16
| | | | back-stamped for this.
* Code review for XML patch. Instill a bit of sanity in the location ofTom Lane2006-12-242-2/+30
| | | | | | | the XmlExpr code in various lists, use a representation that has some hope of reverse-listing correctly (though it's still a de-escaping function shy of correctness), generally try to make it look more like Postgres coding conventions.
* Clean up local redeclarations of variables with DLLIMPORT, per reportTom Lane2006-10-191-3/+2
| | | | from Magnus that MSVC complains about this.
* pgindent run for 8.2.Bruce Momjian2006-10-044-74/+76
|
* Fix bugs in plpgsql and ecpg caused by assuming that isspace() would onlyTom Lane2006-09-222-6/+7
| | | | | | | | | return true for exactly the characters treated as whitespace by their flex scanners. Per report from Victor Snezhko and subsequent investigation. Also fix a passel of unsafe usages of <ctype.h> functions, that is, ye olde char-vs-unsigned-char issue. I won't miss <ctype.h> when we are finally able to stop using it.
* Change processing of extended-Query mode so that an unnamed statementTom Lane2006-09-061-1/+2
| | | | | | | | that has parameters is always planned afresh for each Bind command, treating the parameter values as constants in the planner. This removes the performance penalty formerly often paid for using out-of-line parameters --- with this definition, the planner can do constant folding, LIKE optimization, etc. After a suggestion by Andrew@supernews.
* Add new return codes SPI_OK_INSERT_RETURNING etc to the SPI API.Tom Lane2006-08-271-20/+7
| | | | | | | Fix all the standard PLs to be able to return tuples from FOO_RETURNING statements as well as utility statements that return tuples. Also, fix oversight that SPI_processed wasn't set for a utility statement returning tuples. Per recent discussion.
* Add hooks to allow debugging and performance measurement pluginsTom Lane2006-08-153-3/+105
| | | | to instrument PL/pgSQL. Korry Douglas
* Support INSERT/UPDATE/DELETE RETURNING in plpgsql, with rowcount checkingTom Lane2006-08-145-342/+359
| | | | | | as per yesterday's proposal. Also make things a tad more orthogonal by adding the recent STRICT addition to EXECUTE INTO. Jonah Harris and Tom Lane
* Get rid of "lookahead" functionality in plpgsql's yylex() function,Tom Lane2006-08-142-158/+142
| | | | | | | | | | | | | | | | | | | | | | and instead make the grammar production for the RETURN statement do the heavy lifting. The lookahead idea was copied from the main parser, but it does not work in plpgsql's parser because here gram.y looks explicitly at the scanner's yytext variable, which will be out of sync after a failed lookahead step. A minimal example is create or replace function foo() returns void language plpgsql as ' begin perform return foo bar; end'; which can be seen by testing to deliver "foo foo bar" to the main parser instead of the expected "return foo bar". This isn't a huge bug since RETURN is not found in the main grammar, but it could bite someone who tried to use "return" as an identifier. Back-patch to 8.1. Bug exists further back, but HEAD patch doesn't apply cleanly, and given the lack of field complaints it doesn't seem worth the effort to develop adjusted patches.
* Add a feature for automatic initialization and finalization of dynamicallyTom Lane2006-08-082-33/+11
| | | | | | | | | loaded libraries: call functions _PG_init() and _PG_fini() if the library defines such symbols. Hence we no longer need to specify an initialization function in preload_libraries: we can assume that the library used the _PG_init() convention, instead. This removes one source of pilot error in use of preloaded libraries. Original patch by Ralf Engelschall, preload_libraries changes by me.
* Allow include files to compile own their own.Bruce Momjian2006-07-131-1/+2
| | | | | | | Strip unused include files out unused include files, and add needed includes to C files. The next step is to remove unused include files in C files.
* Alphabetically order reference to include files, "N" - "S".Bruce Momjian2006-07-112-4/+4
|
* Code review for SELECT INTO STRICT patch: use saner choices of errorTom Lane2006-06-164-15/+13
| | | | SQLSTATEs, fix some documentation problems.
* Fix problems with cached tuple descriptors disappearing while still in useTom Lane2006-06-161-16/+19
| | | | | | | | | | by creating a reference-count mechanism, similar to what we did a long time ago for catcache entries. The back branches have an ugly solution involving lots of extra copies, but this way is more efficient. Reference counting is only applied to tupdescs that are actually in caches --- there seems no need to use it for tupdescs that are generated in the executor, since they'll go away during plan shutdown by virtue of being in the per-query memory context. Neil Conway and Tom Lane
* Add STRICT to PL/pgSQL SELECT INTO, so exceptions are thrown if more orBruce Momjian2006-06-155-11/+49
| | | | | | | | | less than one row is returned by the SELECT, for Oracle PL/SQL compatibility. Improve SELECT INTO documentation. Matt Miller
* Add BY clause to PL/PgSQL FOR loop, to control the iteration increment.Bruce Momjian2006-06-125-9/+62
| | | | Jaime Casanova
* Magic blocks don't do us any good unless we use 'em ... so install oneTom Lane2006-05-301-1/+3
| | | | in every shared library.
* Revert patch, needs more work:Bruce Momjian2006-05-305-352/+37
| | | | | | | | | | | | | | --------------------------------------------------------------------------- Add dynamic record inspection to PL/PgSQL, useful for generic triggers: tval2 := r.(cname); or columns := r.(*); Titus von Boxberg
* Add dynamic record inspection to PL/PgSQL, useful for generic triggers:Bruce Momjian2006-05-305-37/+352
| | | | | | | | | | tval2 := r.(cname); or columns := r.(*); Titus von Boxberg
* Back out patch, wrong previous commit message.Bruce Momjian2006-05-305-352/+37
|
* Add regexp_replace() to string functions section.Bruce Momjian2006-05-305-37/+352
| | | | Joachim Wieland
* TG_table_name and TG_table_schema for plpgsql, plus docs and regression.Andrew Dunstan2006-05-283-3/+34
|
* Revert ill-considered change to plpgsql: it should not rely on theTom Lane2006-05-271-4/+8
| | | | | | current setting of standard_conforming_strings to decide how to quote strings that will be used later. There is much more to do here but this particular change breaks the build on Windows, so fix it now.
* Use E'' strings internally only when standard_conforming_strings =Bruce Momjian2006-05-261-3/+4
| | | | | | | | | 'off'. This allows pg_dump output with standard_conforming_strings = 'on' to generate proper strings that can be loaded into other databases without the backslash doubling we typically do. I have added the dumping of the standard_conforming_strings value to pg_dump. I also added standard backslash handling for plpgsql.
* Simplify ParamListInfo data structure to support only numbered parameters,Tom Lane2006-04-221-16/+19
| | | | | | | not named ones, and replace linear searches of the list with array indexing. The named-parameter support has been dead code for many years anyway, and recent profiling suggests that the searching was costing a noticeable amount of performance for complex queries.