Re: missing semicolon at end of psql files - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: missing semicolon at end of psql files
Date
Msg-id 1347507447.18266.2.camel@vanquo.pezone.net
Whole thread Raw
In response to missing semicolon at end of psql files  (Peter Eisentraut <peter_e@gmx.net>)
List 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.





pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: git author vs committer
Next
From: "Kevin Grittner"
Date:
Subject: Re: Comment typo