Create table if not exists ... how ??

Поиск
Список
Период
Сортировка
От Jennifer Trey
Тема Create table if not exists ... how ??
Дата
Msg-id AANLkTikaCWrB_Dd-s4adMisqd-YR3wMudBi3yLYLcE1V@mail.gmail.com
обсуждение исходный текст
Ответы Re: Create table if not exists ... how ??  (Raymond O'Donnell <rod@iol.ie>)
Re: Create table if not exists ... how ??  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: Create table if not exists ... how ??  (Joe Conway <mail@joeconway.com>)
Re: Create table if not exists ... how ??  (Scott Marlowe <scott.marlowe@gmail.com>)
Список pgsql-general
I can't figure out the correct syntax...

I have this, but it just keeps complaining about the IF 

IF NOT EXISTS (SELECT table_name FROM information_schema.tables where table_name = 'post_codes')

THEN

CREATE TABLE post_codes
(
  area character varying(10) NOT NULL,
  district character varying(10) NOT NULL,
  sector character varying(10) NOT NULL,
  CONSTRAINT post_codes_pkey PRIMARY KEY (area, district, sector)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE post_codes OWNER TO postgres;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ERROR:  syntax error at or near "IF"
LINE 1: IF NOT EXISTS (SELECT table_name FROM information_schema.tab...
        ^

********** Error **********

ERROR: syntax error at or near "IF"
SQL state: 42601
Character: 1


How should this be written ? 

Thanks, Jen

В списке pgsql-general по дате отправления:

Предыдущее
От: arno
Дата:
Сообщение: Re: index scan and functions
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: Create table if not exists ... how ??