Re: why semicolon after begin is not allowed in postgresql? - Mailing list pgsql-hackers

From Kevin Grittner
Subject Re: why semicolon after begin is not allowed in postgresql?
Date
Msg-id 1385160186.72261.YahooMailNeo@web162902.mail.bf1.yahoo.com
Whole thread Raw
In response to why semicolon after begin is not allowed in postgresql?  (AK <alkuzo@gmail.com>)
Responses Re: why semicolon after begin is not allowed in postgresql?  (AK <alkuzo@gmail.com>)
List pgsql-hackers
AK <alkuzo@gmail.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



pgsql-hackers by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: why semicolon after begin is not allowed in postgresql?
Next
From: Andrew Dunstan
Date:
Subject: Re: why semicolon after begin is not allowed in postgresql?