Re: a few small bugs in plpgsql

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: a few small bugs in plpgsql
Date: 2010-10-08 01:19:10
Message-ID: AANLkTikNufRjcHRd1nNNwKxhWovD_4sZ5A3RpW1mbPoM@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 7, 2010 at 2:53 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hello,
>
> today I found a few bugs:
>
> a) parser allow a labels on invalid positions with strange runtime bug:
>
> postgres=# CREATE OR REPLACE FUNCTION foo()
> RETURNS void AS $$
> BEGIN
>  FOR i IN 1..2
>  <<<invalidLabel>>
>  LOOP
>    RAISE NOTICE '%',i;
>  END LOOP;
> END;
> $$ LANGUAGE plpgsql;
> CREATE FUNCTION
>
> ERROR:  column "invalidlabel" does not exist
> LINE 2:   <<<invalidLabel>>
>             ^
> QUERY:  SELECT 2
>  <<<invalidLabel>>
> CONTEXT:  PL/pgSQL function "foo" line 3 at FOR with integer loop variable
> postgres=#

I'm not sure if I'd call that a bug, but it does look like a somewhat
odd error message, at least at first glance.

> b) SRF functions must not be finished by RETURN statement - I know, so
> there is outer default block, but it looks like inconsistency for SRF
> functions, because you can use a RETURN NEXT without RETURN. It maybe
> isn't bug - but I am filling it as inconsistency.
>
> postgres=# CREATE OR REPLACE FUNCTION fg(OUT i int)
> RETURNS SETOF int AS $$
> BEGIN
>  FOR i IN 1..3
>  LOOP fg.i := i;
>    RETURN NEXT;
>  END LOOP;
> END;
> $$ LANGUAGE plpgsql;
> CREATE FUNCTION
>
> postgres=# select fg();
>  fg
> ----
>  1
>  2
>  3
> (3 rows)

I don't see what's wrong with this.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2010-10-08 01:35:14 Re: a few small bugs in plpgsql
Previous Message Josh Berkus 2010-10-08 00:49:22 GIN vs. Partial Indexes