Re: create table as problem

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: create table as problem
Дата
Msg-id 20060915210047.GA33331@winnie.fuhr.org
обсуждение исходный текст
Ответ на create table as problem  (garry saddington <garry@schoolteachers.co.uk>)
Список pgsql-general
On Fri, Sep 15, 2006 at 09:42:35PM +0100, garry saddington wrote:
> I am getting a syntax error at or near 'as' in this method, can anyone
> help?
>
> create table iclasses
> (classid serial,
> subject text,
> year text,
> groups text,
> teacher text,
> set text
> )
> as select distinct subject,year,groups,teacher,set from interimclasses

With CREATE TABLE AS you can specify column names but not column
types.  If you want to create more columns than the query returns
then try an ordinary CREATE TABLE followed by INSERT INTO ... SELECT.

CREATE TABLE iclasses (
    classid  serial,
    subject  text,
    year     text,
    groups   text,
    teacher  text,
    set      text
);

INSERT INTO iclasses (subject, year, groups, teacher, set)
  SELECT DISTINCT subject, year, groups, teacher, set
  FROM interimclasses;

--
Michael Fuhr

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

Предыдущее
От: garry saddington
Дата:
Сообщение: create table as problem
Следующее
От: Poul Jensen
Дата:
Сообщение: Re: ECPG: non-integer constant in group by