株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

Postgresでは、CREATE DATABASE IF NOT EXIST testのようなことはできない。
そのため、IF NOT EXISTS部分を自力で作る必要がある。

DO $$

BEGIN
  IF EXISTS (SELECT FROM pg_database WHERE datname = 'testdb') THEN
    RAISE NOTICE 'Database already exists';
  ELSE
    CREATE DATABASE testdb;
  END IF;
END $$

RAISEは標準出力するクエリ

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)