Sample Header Ad - 728x90

How to verify, that a DB hive already exists?

1 vote
1 answer
3826 views
We create a hive database using expect script and with some other commands. In the case if we run the expect script again on the machine that hive already created, we get this: > ERROR hive already exists How can we check if *database hive already created* before creating it again? And by this verification we can escape the *expect script*: # su - postgres Last login: Sun Aug 13 11:12:03 UTC 2017 on pts/0 -bash-4.2$ psql psql (9.2.13) Type "help" for help. postgres=# CREATE DATABASE hive; ERROR: database "hive" already exists My expect script: (from my bash script) set timeout -1 #exec the scripts spawn timeout 60 ssh root@IP expect "#" spawn su - postgres expect "$" send "psql\n" expect "=#" send "CREATE DATABASE hive;\n" . . . . Other example: postgres=# CREATE DATABASE [IF NOT EXISTS] hive; ERROR: syntax error at or near "[" LINE 1: CREATE DATABASE [IF NOT EXISTS] hive; ^
Asked by yael (13936 rep)
Aug 13, 2017, 01:56 PM
Last activity: Aug 21, 2017, 04:06 PM