title: postgresql if not exist reports syntax error "IF"
body: <p>I was trying to create database and tables with commands:</p>
  <pre><code>\i 'D:/Project/data/Create database tables.sql';
  </code></pre>
  <p>But it reports syntax error &quot;IF&quot;.</p>
  <p>I searched for solutions. Some mentioned that adding <code>DO $do$ BEGIN</code> and <code>END $$</code> will work. But it reports an error as well <code> ERROR:  unterminated dollar-quoted string at or near &quot;$do$</code></p>
  <p>I'm not familiar with sql language. May I ask how to successfully create database and tables using the script. Thanks.</p>
  <p>Below is <code>create database and table</code> sql script:</p>
  <pre><code>IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = '[abc]')
    BEGIN 
      CREATE DATABASE [abc]   
      END 
      GO  
      
      USE [abc]
      GO  
  
  SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  /****** Object:  Table [dbo].[DEMOGRAPHICS]    ************/
  
  
  CREATE TABLE [dbo].[DEMOGRAPHICS](
      [caseid] [bigint] NULL,
      [primaryid] [bigint] NULL,
      [caseversion] [int] NULL,
      [fda_dt] [int] NULL,
      [I_F_COD] [varchar](1) NULL,
      [event_dt] [int] NULL,
      [AGE] [float] NULL,
      [Gender] [varchar](3) NULL,
      [COUNTRY_CODE] [varchar](2) NULL,
      [Period] [varchar](4) NULL
  ) ON [PRIMARY]
  GO
  </code></pre>