Search Postgresql Archives

Re: Create table if not exists ... how ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

you can use IF statement only inside plpgsql function. CREATE TABLE
doesn't support clause IF.

Regards

Pavel Stehule

2010/7/19 Jennifer Trey <jennifer.trey@xxxxxxxxx>:
> 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
>

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux