Re: Issues on Insert Data From Existing Table

Поиск
Список
Период
Сортировка
От Raymond O'Donnell
Тема Re: Issues on Insert Data From Existing Table
Дата
Msg-id 4D1F8C7D.9010403@iol.ie
обсуждение исходный текст
Ответ на Issues on Insert Data From Existing Table  (vwu98034@lycos.com)
Список pgsql-general
On 01/01/2011 19:49, vwu98034@lycos.com wrote:
> I need to update the database schema to add a new table based on an
> original table. The existing table is the following:
>
> create table shop_image ( id                SERIAL UNIQUE primary key, shop_fk
> int references vsm_shop (id) on delete cascade, path            varchar(255),
> title        varchar(80), sentence    text, placement    varchar(6), sequence
> int2 );
>
> and the new table is the following:
>
> create table shop_image_narrative ( image_fk     int references
> shop_image (id) on delete cascade, lang        char(2) not null, title
> varchar(80), sentence    text, placement    varchar(6) );
>
> When I run the following query
>
> INSERT INTO shop_image_narrative (image_fk,title,sentence,placement)
> select (id,title,sentence,placement) from shop_image;
>
> to move data from the existing table to the new one, I run into the
> following error
>
> 22:08:06  [INSERT - 0 row(s), 0.000 secs]  [Error Code: 0, SQL State:
> 42804]  ERROR: column "image_fk" is of type integer but expression is
> of type record

Remove the parentheses from your SELECT:

INSERT INTO.... SELECT id, title, sentence, placement from shop_image;

> My another question is how to insert a constant to a field while the
> rest data from the data in another table?

Just include it as a literal in the SELECT part:

INSERT INTO.... SELECT id, 'foo', .....

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

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

Предыдущее
От: vwu98034@lycos.com
Дата:
Сообщение: Issues on Insert Data From Existing Table
Следующее
От: Andre Lopes
Дата:
Сообщение: How to deal with field on the database that stores variable array's?