Re: BUG #13889: psql doesn't exequte correct script

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: v_bilyak(at)mail(dot)ru
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13889: psql doesn't exequte correct script
Date: 2016-01-25 20:47:13
Message-ID: CAFj8pRBbeiHgX8A+QyqEAX5D70Mk+FBc__gmrADMA_3c2STbRQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi

2016-01-25 18:09 GMT+01:00 <v_bilyak(at)mail(dot)ru>:

> The following bug has been logged on the website:
>
> Bug reference: 13889
> Logged by: Vladimir
> Email address: v_bilyak(at)mail(dot)ru
> PostgreSQL version: 9.5.0
> Operating system: Windows 10
> Description:
>
> Hello. I faced the following issue: psql.exe does not execute the following
> script
>
> DROP DATABASE "demo_crash";
> CREATE DATABASE "demo_crash";
>
> aborting with error:
>
> CREATE DATABASE cannot be executed from a function or multi-command string
>

> I searched in Google for solution but found only suggestion to rebuild
> Postgres with some fix in source code that is not acceptable in my case. Do
> you have another suggestion how to resolve it? Thank you in advance for any
> help!
>

It isn't bug. You probably use "-c" option. All statements executed by this
option are executed in one transaction. Some statements like CREATE
DATABASE or DROP DATABASE cannot be called from transaction.

[pavel(at)dhcppc2 ~]$ psql -c "DROP DATABASE demo_crash; CREATE DATABASE
demo_crash" postgres
Debug assertions "off"
ERROR: 25001: DROP DATABASE cannot be executed from a function or
multi-command string
LOCATION: PreventTransactionChain, xact.c:3158
Time: 0.488 ms

The solution is in next release 9.6, that allows multiple -c options

[pavel(at)dhcppc2 ~]$ psql -c "DROP DATABASE demo_crash" -c "CREATE DATABASE
demo_crash" postgres
Debug assertions "off"
ERROR: 3D000: database "demo_crash" does not exist
LOCATION: dropdb, dbcommands.c:797
Time: 0.399 ms
CREATE DATABASE
Time: 711.694 ms

For current release use echo and pipe

[pavel(at)dhcppc2 ~]$ echo "DROP DATABASE demo_crash; CREATE DATABASE
demo_crash" | psql postgres
Debug assertions "off"
DROP DATABASE
Time: 224.953 ms
CREATE DATABASE
Time: 742.695 ms

I have not windows, but it should work

Regards

Pavel

>
> Sincerely,
> Vladimir
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Geoghegan 2016-01-25 22:42:04 Re: BUG #13886: When INSERT ON CONFLICT DO UPDATE updates, it returns INSERT rather than UPDATE
Previous Message Vitaly Burovoy 2016-01-25 19:55:52 Re: BUG #13883: Very Important Facility