Re: why semicolon after begin is not allowed in postgresql?

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: AK <alkuzo(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: why semicolon after begin is not allowed in postgresql?
Date: 2013-11-22 22:43:06
Message-ID: 1385160186.72261.YahooMailNeo@web162902.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

AK <alkuzo(at)gmail(dot)com> wrote:

> I am reading the following in the documentation: "Tip: A common
> mistake is to write a semicolon immediately after BEGIN. This is
> incorrect and will result in a syntax error."
>
> So, "common mistake" means semicolons after BEGIN seem consistent
> to many people - it seems consistent to me as well. If PostgreSql
> allowed them, we would have one less rule to memorize, shorter
> documentation, less mistakes and so on. In other words, without
> this limitation PostgreSql would be slightly more useful, right?
>
> What am I missing? Why do we need this rule? How is it making
> PostgreSql better?

I think it only seems confusing because PostgreSQL also uses BEGIN
as a synonym for START TRANSACTION (and people tend to use the
shorter synonym to save keystrokes).  In plpgsql BEGIN is not a
command, it is part of declaring a code block.  Wouldn't these look
funny to you?:

IF x = 1 THEN;
  ...
END IF;

CASE;
  WHEN x = 1 THEN
    ...
  WHEN x = 2 THEN
    ...
  ELSE
    ...
END;

LOOP;
  ...
END LOOP;

etc.

Why should BEGIN be different from the above when it is not a
command, but part of declaring a code block?

In the nearest analog in the SQL standard, the BEGIN/END block is
called a compound statement, and like any other statement it is
ended by a semicolon; the standard does not allow a semicolon after
the BEGIN.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2013-11-22 22:44:48 Re: why semicolon after begin is not allowed in postgresql?
Previous Message Merlin Moncure 2013-11-22 22:38:51 Re: why semicolon after begin is not allowed in postgresql?