bcgov / bcgov/cas-postgres

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

Open
#99 0 comments 0 reactions 0 assignees View on GitHub
Tech Debt
Dominant language
Shell
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.