Commit Graph

271 Commits

Author SHA1 Message Date
Tom Lane c3a153afed Tweak palloc/repalloc to allow zero bytes to be requested, as per recent
proposal.  Eliminate several dozen now-unnecessary hacks to avoid palloc(0).
(It's likely there are more that I didn't find.)
2004-06-05 19:48:09 +00:00
Tom Lane 7eb2ff799e Support assignment to whole-row variables in plpgsql; also fix glitch
with using a trigger's NEW or OLD record as a whole-row variable in an
expression.  Fixes several long-standing complaints.
2004-06-04 02:37:06 +00:00
Tom Lane 0f059e1d13 Allow plpgsql to pass composite-type arguments (ie, whole-row variables)
into SQL expressions.  At present this only works usefully for variables
of named rowtypes, not RECORD variables, since the SQL parser can't infer
anything about datatypes from a RECORD Param.  Still, it's a step forward.
2004-06-04 00:07:52 +00:00
Tom Lane 724c706400 Restructure plpgsql's parsing of datatype declarations to unify the
scalar and composite (rowtype) cases a little better.  This commit is
just a code-beautification operation and shouldn't make any real
difference in behavior, but it's an important preliminary step for
trying to improve plgsql's handling of rowtypes.
2004-06-03 22:56:43 +00:00
Tom Lane 238dc4634f plpgsql hasn't needed -Wno-error for a good long while. 2004-06-03 19:21:31 +00:00
Neil Conway 72b6ad6313 Use the new List API function names throughout the backend, and disable the
list compatibility API by default. While doing this, I decided to keep
the llast() macro around and introduce llast_int() and llast_oid() variants.
2004-05-30 23:40:41 +00:00
Neil Conway d0b4399d81 Reimplement the linked list data structure used throughout the backend.
In the past, we used a 'Lispy' linked list implementation: a "list" was
merely a pointer to the head node of the list. The problem with that
design is that it makes lappend() and length() linear time. This patch
fixes that problem (and others) by maintaining a count of the list
length and a pointer to the tail node along with each head node pointer.
A "list" is now a pointer to a structure containing some meta-data
about the list; the head and tail pointers in that structure refer
to ListCell structures that maintain the actual linked list of nodes.

The function names of the list API have also been changed to, I hope,
be more logically consistent. By default, the old function names are
still available; they will be disabled-by-default once the rest of
the tree has been updated to use the new API names.
2004-05-26 04:41:50 +00:00
Tom Lane 2f63232d30 Promote row expressions to full-fledged citizens of the expression syntax,
rather than allowing them only in a few special cases as before.  In
particular you can now pass a ROW() construct to a function that accepts
a rowtype parameter.  Internal generation of RowExprs fixes a number of
corner cases that used to not work very well, such as referencing the
whole-row result of a JOIN or subquery.  This represents a further step in
the work I started a month or so back to make rowtype values into
first-class citizens.
2004-05-10 22:44:49 +00:00
Tom Lane 6c72f44c62 Improve syntax error messages for invalid-argument cases in RETURN and
RETURN NEXT.
2004-04-15 13:01:45 +00:00
Tom Lane 375369acd1 Replace TupleTableSlot convention for whole-row variables and function
results with tuples as ordinary varlena Datums.  This commit does not
in itself do much for us, except eliminate the horrid memory leak
associated with evaluation of whole-row variables.  However, it lays the
groundwork for allowing composite types as table columns, and perhaps
some other useful features as well.  Per my proposal of a few days ago.
2004-04-01 21:28:47 +00:00
Tom Lane 457ad3925d Add a more useful error message for the case where someone tries to pass
a whole row or record variable into a SQL function.  Eventually this case
should be made to actually work, but for now this is better than what it
did before.
2004-03-24 23:38:49 +00:00
Bruce Momjian a7f0747320 Adds DLLIMPORT modifier to check_function_bodies
Claudio Natoli
2004-03-22 03:15:33 +00:00
Tom Lane f938c2b91b Revise syntax-error reporting behavior to give pleasant results for
errors in internally-generated queries, such as those submitted by
plpgsql functions.  Per recent discussions with Fabien Coelho.
2004-03-21 22:29:11 +00:00
Tom Lane 0fdc6c4cc0 Create a validator for plpgsql, so that some minimal syntax checking
is done at creation time for plpgsql functions.  Improve createlang and
droplang to support adding/dropping validators for PLs.  Initial steps
towards producing a syntax error position from plpgsql syntax errors
(this part is a work in progress, and will change depending on outcome
of current discussions).
2004-03-19 18:58:07 +00:00
Tom Lane 55f7c3300d Reimplement CASE val WHEN compval1 THEN ... WHEN compval2 THEN ... END
so that the 'val' is computed only once, per recent discussion.  The
speedup is not much when 'val' is just a simple variable, but could be
significant for larger expressions.  More importantly this avoids issues
with multiple evaluations of a volatile 'val', and it allows the CASE
expression to be reverse-listed in its original form by ruleutils.c.
2004-03-17 20:48:43 +00:00
Tom Lane 5ada9ef088 Teach plpgsql's lexer about dollar-quoted literals.
Andrew Dunstan, some help from Tom Lane.
2004-02-25 18:10:51 +00:00
Tom Lane fa96a5e15b Add %option nodefault to all our flex lexers. Fix a couple of rule gaps
exposed thereby.  AFAICT these would not lead to any worse problems than
junk emitted on the backend's stdout, but we should have the option to
catch possible worse errors in future.
2004-02-24 22:06:32 +00:00
Tom Lane 55fb172739 Don't crash when a rowtype argument to a plpgsql function is NULL.
Per report from Chris Campbell.
2004-02-24 01:44:33 +00:00
Tom Lane 59f9a0b9df Implement a solution to the 'Turkish locale downcases I incorrectly'
problem, per previous discussion.  Make some additional changes to
centralize the knowledge of just how identifier downcasing is done,
in hopes of simplifying any future tweaking in this area.
2004-02-21 00:34:53 +00:00
Tom Lane 0eb6951915 Repair missing inclusions of -lintl for shared libraries. 2004-02-10 07:26:25 +00:00
Tom Lane 391c3811a2 Rename SortMem and VacuumMem to work_mem and maintenance_work_mem.
Make btree index creation and initial validation of foreign-key constraints
use maintenance_work_mem rather than work_mem as their memory limit.
Add some code to guc.c to allow these variables to be referenced by their
old names in SHOW and SET commands, for backwards compatibility.
2004-02-03 17:34:04 +00:00
Neil Conway 192ad63bd7 More janitorial work: remove the explicit casting of NULL literals to a
pointer type when it is not necessary to do so.

For future reference, casting NULL to a pointer type is only necessary
when (a) invoking a function AND either (b) the function has no prototype
OR (c) the function is a varargs function.
2004-01-07 18:56:30 +00:00
Tom Lane 304d6d5b63 Support function parameter names in plpgsql. This is the last of
Dennis Bjorklund's original patch for function parameter names, but
there's still plenty left to do (documentation for instance...)
2004-01-07 06:20:02 +00:00
Tom Lane a77e32d7c5 Apply the core parts of Dennis Bjorklund's patch to allow function
parameters to be declared with names.  pg_proc has a column to store
names, and CREATE FUNCTION can insert data into it, but that's all as
yet.  I need to do more work on the pg_dump and plpgsql portions of the
patch before committing those, but I thought I'd get the bulky changes
in before the tree drifts under me.
initdb forced due to pg_proc change.
2004-01-06 23:55:19 +00:00
Tom Lane f66b0ff066 Allow plpgsql variables' default value expressions to reference
existing variables (such as function parameters).  Per gripe from
David Fetter.
2003-12-23 00:01:57 +00:00
PostgreSQL Daemon 969685ad44 $Header: -> $PostgreSQL Changes ... 2003-11-29 19:52:15 +00:00
Tom Lane 3108b5db28 Allow the query for a plpgsql cursor to begin with '(' as well as 'SELECT'.
Per example from Kumar, 30-Oct-03.
2003-10-30 17:18:55 +00:00
Tom Lane 04b40923d6 Add code to check that IF/WHILE/EXIT test expressions are boolean,
and try to coerce the values to boolean if not.  Per recent discussions.
2003-10-01 21:47:42 +00:00
Tom Lane 47ed658c59 heap_open => relation_open to avoid unwanted restriction on relkind.
Per gripe from Gaetano Mendola.
2003-09-30 00:59:51 +00:00
Tom Lane 8b510838f6 Restructure plpgsql's caching of 'simple' expression evaluation trees
to be less dangerous, and often faster as well.  ExprState trees are
not kept across transaction boundaries; this eliminates problems with
resource leakage in failed transactions.  But by keeping them in a
per-transaction EState, we can safely arrange for a single ExprState
to be shared by all the expression evaluations done in a given plpgsql
function call.  (Formerly it seemed necessary to create and destroy an
ExprState for each exec_eval_simple_expr() call.)  This saves time in
any scenario where a plpgsql function executes more than one expression.
Seems to be about as fast as 7.3 for simple cases, and significantly
faster for functions that do a lot of calculations.
2003-09-28 23:37:45 +00:00
Tom Lane 2848dc5fea Make the world safe (more or less) for dropped columns in plpgsql rowtypes. 2003-09-25 23:02:12 +00:00
Tom Lane 23e10843db When compiling a plpgsql trigger function, include the OID of the table
the trigger is attached to in the hashkey.  This ensures that we will
create separate compiled trees for each table the trigger is used with,
avoiding possible datatype-mismatch problems if the tables have different
rowtypes.  This is essentially the same bug recently identified in plpython
--- though plpgsql doesn't seem as prone to crash when the rowtype changes
underneath it.  But failing robustly is no substitute for just working.
2003-08-18 19:16:02 +00:00
Tom Lane 635d00ecea Avoid malloc(0). Although standard mallocs seem not to object,
some debugging malloc packages do.
2003-08-08 19:19:32 +00:00
Bruce Momjian 089003fb46 pgindent run. 2003-08-04 00:43:34 +00:00
Tom Lane 8b1ea2f58b Cause library-preload feature to report error if specified initialization
function is not found.  Also, make all the PL libraries have initialization
functions with standard names.  Patch from Joe Conway.
2003-07-31 18:36:46 +00:00
Tom Lane 81b5c8a136 A visit from the message-style police ... 2003-07-28 00:09:16 +00:00
Tom Lane b556e8200e elog mop-up: bring some straggling fprintf(stderr)'s into the elog world. 2003-07-27 21:49:55 +00:00
Tom Lane e7f3645171 Fix some localizability issues with existing errcontext() calls. 2003-07-27 18:38:26 +00:00
Tom Lane e8db9b26d0 elog mop-up. 2003-07-27 17:10:07 +00:00
Bruce Momjian 1be17f1f26 >>You can alias $0, similar to the argument variables. And, I confirmed
>>that you cannot change the value, similar to the argument variables:
>
> Perhaps you shouldn't mark it isconst; then it would actually have some
> usefulness (you could use it directly as a temporary variable to hold
> the intended result).  I can't see much value in aliasing it if it's
> const, either.

OK; the only change in this version is "isconst = false;". Now you can
use $0 as a result placeholder if desired. E.g.:

create or replace function tmp(anyelement, anyelement) returns anyarray as '
declare
  v_ret alias for $0;
  v_el1 alias for $1;
  v_el2 alias for $2;
begin
  v_ret := ARRAY[v_el1, v_el2];
  return v_ret;
end;
' language 'plpgsql';

create table f(f1 text, f2 text, f3 int, f4 int);
insert into f values ('a','b',1,2);
insert into f values ('z','x',3,4);

select tmp(f1,f2) from f;
select tmp(f3,f4) from f;


Joe Conway
2003-07-26 23:58:23 +00:00
Tom Lane 3b04893ffc Error message editing in src/pl. The plpython module could use another
look ... I'm not real certain which errors are strictly internal and which
are likely to be provoked by users.
2003-07-25 23:37:31 +00:00
Tom Lane b837c99210 Support polymorphic functions in plpgsql. Along the way, replace
linked-list search of function cache with hash-table lookup.
By Joe Conway.
2003-07-01 21:47:09 +00:00
Tom Lane bee217924d Support expressions of the form 'scalar op ANY (array)' and
'scalar op ALL (array)', where the operator is applied between the
lefthand scalar and each element of the array.  The operator must
yield boolean; the result of the construct is the OR or AND of the
per-element results, respectively.

Original coding by Joe Conway, after an idea of Peter's.  Rewritten
by Tom to keep the implementation strictly separate from subqueries.
2003-06-29 00:33:44 +00:00
Tom Lane 1bd22f55cf Disallow dollar sign in operator names, instead allow it as a non-first
character in identifiers.  The first change eliminates the current need
to put spaces around parameter references, as in "x<=$2".  The second
change improves compatibility with Oracle and some other RDBMSes.  This
was discussed and agreed to back in January, but did not get done.
2003-06-19 23:22:40 +00:00
Tom Lane f12f8990e4 Fix error line numbers reported for errors in plpgsql_parse_word and
siblings.
2003-06-17 04:35:03 +00:00
Tom Lane 5666462f2e Ensure that in all flex lexers that are part of the backend, a
yy_fatal_error() call results in elog(ERROR) not exit().  This was
already fixed in the main lexer and plpgsql, but extend same technique
to all the other dot-l files.  Also, on review of the possible calls
to yy_fatal_error(), it seems safe to use elog(ERROR) not elog(FATAL).
2003-05-29 22:30:02 +00:00
Bruce Momjian 98b6f37e47 Make debug_ GUC varables output DEBUG1 rather than LOG, and mention in
docs that CLIENT/LOG_MIN_MESSAGES now controls debug_* output location.
Doc changes included.
2003-05-27 17:49:47 +00:00
Tom Lane 450d7e276e Seems pl_funcs didn't have support for plpgsql PERFORM statement. 2003-05-23 04:08:34 +00:00
Tom Lane 20aea2ec7b Alter plpgsql's lexer so that yylineno and yymore are not used. This
avoids 'input buffer overflow' failure on long literals, improves
performance, gives the right answer for line position in functions
containing multiline literals, suppresses annoying compiler warnings,
and generally is so much better I wonder why we didn't do it before.
2003-05-05 16:46:28 +00:00
Tom Lane 4089d25175 Fix plpgsql so that variables of composite types (rowtypes) can be
declared without having to write %ROWTYPE.  If the declared type of
a variable is a composite type, it'll be taken to be a row variable
automatically.
2003-04-27 22:21:22 +00:00