Re: InitPostgres and flatfiles question - Mailing list pgsql-hackers

From Tom Lane
Subject Re: InitPostgres and flatfiles question
Date
Msg-id 17180.1167925008@sss.pgh.pa.us
Whole thread Raw
In response to Re: InitPostgres and flatfiles question  (Markus Schiltknecht <markus@bluegap.ch>)
Responses Re: InitPostgres and flatfiles question  (Mario Weilguni <mweilguni@sime.com>)
Re: InitPostgres and flatfiles question  (Markus Schiltknecht <markus@bluegap.ch>)
Re: InitPostgres and flatfiles question  (Bruce Momjian <bruce@momjian.us>)
Re: InitPostgres and flatfiles question  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
Markus Schiltknecht <markus@bluegap.ch> writes:
> I've just found the stumbling block: the -c option of psql wraps all in 
> a transaction, as man psql says:
> ...
> Thank you for clarification, I wouldn't have expected that (especially 
> because CREATE DATABASE itself says, it cannot be run inside a 
> transaction block... A transaction block (with BEGIN and COMMIT) seems 
> to be more than just a transaction, right?)

Hm, that's an interesting point.  psql's -c just shoves its whole
argument string at the backend in one PQexec(), instead of dividing
at semicolons as psql does with normal input.  And so it winds up as
a single transaction because postgres.c doesn't force a transaction
commit until the end of the querystring.  But that's not a "transaction
block" in the normal sense and so it doesn't trigger the
PreventTransactionChain defense in CREATE DATABASE and elsewhere.

I wonder whether we ought to change that?  The point of
PreventTransactionChain is that we don't want the user rolling back
the statement post-completion, but it seems thatpsql -c 'CREATE DATABASE foo; ABORT; BEGIN; ...'
would bypass the check.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Tabs or Spaces
Next
From: Gregory Stark
Date:
Subject: Odd numeric->float4/8 casting behaviour