title: PostgreSQL Exception Handling
body: <p>I am new to PostgreSQL. Could anybody please correct this query.</p>
  
  <pre><code>BEGIN TRANSACTION;
  
  BEGIN;
      CREATE TABLE "Logs"."Events"
      (
          EventId BIGSERIAL NOT NULL PRIMARY KEY,
          PrimaryKeyId bigint NOT NULL,
          EventDateTime date NOT NULL DEFAULT(now()),
          Action varchar(12) NOT NULL,
          UserId integer NOT NULL REFERENCES "Office"."Users"(UserId),
          PrincipalUserId varchar(50) NOT NULL DEFAULT(user)
      );
  
      CREATE TABLE "Logs"."EventDetails"
      (
          EventDetailId BIGSERIAL NOT NULL PRIMARY KEY,
          EventId bigint NOT NULL REFERENCES "Logs"."Events"(EventId),
          Resource varchar(64) NOT NULL,
          OldVal varchar(4000) NOT NULL,
          NewVal varchar(4000) NOT NULL
      );
  
  
      COMMIT TRANSACTION;
      RAISE NOTICE 'Task completed sucessfully.'
  EXCEPTION;
      ROLLBACK TRANSACTION;
      RAISE ERROR @ErrorMessage, @LineNumber, @ErrorState --how to catch errors and display them????
  END;
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>How to print a message like 'PRINT' in T-SQL?</li>
  <li>How to raise errors with exception information?</li>
  </ol>