Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cas-postgres: use postgres_fdw instead of handling errors in create_user_db #99

Open
Dianadec opened this issue Jul 5, 2021 · 0 comments

Comments

@Dianadec
Copy link

Dianadec commented Jul 5, 2021

Something like this (using dblink instead of postgres_fdw) allows to check if a db exists before creating it:

DO
$do$
BEGIN
   IF EXISTS (SELECT FROM pg_database WHERE datname = 'mydb') THEN
      RAISE NOTICE 'Database already exists';  -- optional
   ELSE
      PERFORM dblink_exec('dbname=' || current_database()  -- current db
                        , 'CREATE DATABASE mydb');
   END IF;
END
$do$;

https://www.postgresql.org/docs/current/postgres-fdw.html
postgres-fdw does not come with postgres. It's in the postgres-contrib package

@matthieu-foucault matthieu-foucault transferred this issue from bcgov/cas-ciip-portal Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants