Re: missing semicolon at end of psql files

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: hlinnaka(at)iki(dot)fi
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing semicolon at end of psql files
Date: 2012-09-13 03:37:27
Message-ID: 1347507447.18266.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 2012-09-12 at 17:20 +0300, Heikki Linnakangas wrote:
> On 12.09.2012 17:10, Peter Eisentraut wrote:
> > I was surprised to find that psql -f file.sql with a file such as this
> >
> > select 1;
> > select 2
> >
> > executes both commands even though the second one is not terminated.
> >
> > I realize that this is inconsistently handled throughout the system, for
> > example libpq APIs don't care about the missing semicolon, but
> > interactive psql does.
>
> Even interactive psql doesn't require a semicolon at the end; it's just
> that without it, it doesn't know whether you're still adding to the
> command or if it's finished. But you can also use \g:
>
> ostgres=# select 1
> postgres-# \g
> ?column?
> ----------
> 1
> (1 row)

A \g is equivalent to a semicolon, at least as far as saying, execute
this command now.

Note that

postgres=# select 1
postgres-# <press Ctrl-D here>

does not execute the command before quitting.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2012-09-13 03:40:15 Re: Comment typo
Previous Message Peter Eisentraut 2012-09-13 03:22:50 Re: git author vs committer