Skip to main content
Tweeted twitter.com/StackDBAs/status/1154360785130414081
format code, minor typos, add tags
Source Link
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

I am trying to figure out how to drop multiple databases on PostgreSQL in one sql script. I preferrablypreferably need it to work both when executed in pgAdminpgAdmin console, and when used in psqlpsql command line tool. When I do:


DROP DATABASE db1;
DROP DATABASE db2;
DROP DATABASE db1;
DROP DATABASE db2;

I get following error:

DROP DATABASE cannot be executed from a function or multi-command string

DROP DATABASE cannot be executed from a function or multi-command string

Is there any way around this problem? I.e., is there any way to run each command separately (like when using "GO" statement on MSSQL), or some other sensible way to easily drop multiple databases? I need this functionality for maintenance scripts during development.

I am trying to figure out how to drop multiple databases on PostgreSQL in one sql script. I preferrably need it to work both when executed in pgAdmin console, and when used in psql command line tool. When I do:


DROP DATABASE db1;
DROP DATABASE db2;

I get following error:

DROP DATABASE cannot be executed from a function or multi-command string

Is there any way around this problem? I.e. is there any way to run each command separately (like when using "GO" statement on MSSQL), or some other sensible way to easily drop multiple databases? I need this functionality for maintenance scripts during development.

I am trying to figure out how to drop multiple databases on PostgreSQL in one sql script. I preferably need it to work both when executed in pgAdmin console, and when used in psql command line tool. When I do:

DROP DATABASE db1;
DROP DATABASE db2;

I get following error:

DROP DATABASE cannot be executed from a function or multi-command string

Is there any way around this problem? I.e., is there any way to run each command separately (like when using "GO" statement on MSSQL), or some other sensible way to easily drop multiple databases? I need this functionality for maintenance scripts during development.

Source Link
Tomas
  • 173
  • 1
  • 1
  • 4

Drop multiple databases in one script

I am trying to figure out how to drop multiple databases on PostgreSQL in one sql script. I preferrably need it to work both when executed in pgAdmin console, and when used in psql command line tool. When I do:


DROP DATABASE db1;
DROP DATABASE db2;

I get following error:

DROP DATABASE cannot be executed from a function or multi-command string

Is there any way around this problem? I.e. is there any way to run each command separately (like when using "GO" statement on MSSQL), or some other sensible way to easily drop multiple databases? I need this functionality for maintenance scripts during development.