CREATE DATABASE cannot run inside a transaction block

前端 未结 2 1299
有刺的猬
有刺的猬 2021-01-01 11:34

I am working on AWS server + PostgreSQL. When I execute a query for creating the database I get an error:

CREATE DATABASE cannot run inside a transaction blo         


        
相关标签:
2条回答
  • 2021-01-01 11:35

    Note, for postgres 9.5+ you have to use:

    psql -c '\set AUTOCOMMIT on'
    

    But I'm going to guess, that what you really wanted to do is destroy the database and recreate it in a single command. Here you go:

    printf '\set AUTOCOMMIT on\ndrop database <your_db_here>; create database <your_db_here>; ' |  psql postgres
    
    0 讨论(0)
  • 2021-01-01 11:40

    I have used turn on autocommit in PostgreSQL and it's working for me.

    Here is the query to turn on the autocommit

    SET AUTOCOMMIT = ON
    

    Note that this only works for PostgreSQL 9.4 and below

    0 讨论(0)
提交回复
热议问题