Re: Bug in SQL function with returntype void

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Zíka Aleš, Ing(dot)" <Ales(dot)Zika(at)pel(dot)br(dot)ds(dot)mfcr(dot)cz>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug in SQL function with returntype void
Date: 2003-06-12 17:33:28
Message-ID: 200306121733.h5CHXSC14151@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


Thanks. That bug looked really weird!

---------------------------------------------------------------------------

Tom Lane wrote:
> =?iso-8859-2?Q?=22Z=EDka_Ale=B9=2C_Ing=2E=22?= <Ales(dot)Zika(at)pel(dot)br(dot)ds(dot)mfcr(dot)cz> writes:
> > I tried the example "CREATE FUNCTION clean_EMP () RETURNS void AS
> > 'DELETE FROM EMP WHERE EMP.salary <= 0' LANGUAGE SQL;" in chapter 9.2.1 of
> > Programmer's guide.
> > When the function was invoked, it delete only one tuple, although
> > there were more tuples satisfying the WHERE condition. During secont
> > invocation it deleted next tuple and so on.
>
> Good catch. I've applied the attached patch.
>
> regards, tom lane
>
>
> *** src/backend/executor/functions.c.orig Wed Sep 4 16:31:18 2002
> --- src/backend/executor/functions.c Thu Jun 12 13:26:12 2003
> ***************
> *** 273,289 ****
>
> if (es->qd->operation == CMD_UTILITY)
> {
> - /*
> - * Process a utility command. (create, destroy...) DZ - 30-8-1996
> - */
> ProcessUtility(es->qd->parsetree->utilityStmt, es->qd->dest, NULL);
> - if (!LAST_POSTQUEL_COMMAND(es))
> - CommandCounterIncrement();
> return (TupleTableSlot *) NULL;
> }
>
> ! /* If it's not the last command, just run it to completion */
> ! count = (LAST_POSTQUEL_COMMAND(es)) ? 1L : 0L;
>
> return ExecutorRun(es->qd, es->estate, ForwardScanDirection, count);
> }
> --- 273,291 ----
>
> if (es->qd->operation == CMD_UTILITY)
> {
> ProcessUtility(es->qd->parsetree->utilityStmt, es->qd->dest, NULL);
> return (TupleTableSlot *) NULL;
> }
>
> ! /*
> ! * If it's the function's last command, and it's a SELECT, fetch one
> ! * row at a time so we can return the results. Otherwise just run it
> ! * to completion.
> ! */
> ! if (LAST_POSTQUEL_COMMAND(es) && es->qd->operation == CMD_SELECT)
> ! count = 1L;
> ! else
> ! count = 0L;
>
> return ExecutorRun(es->qd, es->estate, ForwardScanDirection, count);
> }
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2003-06-12 18:00:52 Re: PostgreSQL client has problems when libbind is installed
Previous Message Tom Lane 2003-06-12 17:30:58 Re: Bug in SQL function with returntype void