Re: INSERT INTO problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tom Jenkins <tjenkins(at)devis(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT INTO problem
Date: 2001-02-20 21:11:53
Message-ID: 6534.982703513@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Jenkins <tjenkins(at)devis(dot)com> writes:
> I eventually ended up with this line that still gives me the error:
> insert into reportentity
> select 'D0'||text(departmentid) as reportentityid,
> departmentname as reportentityname,
> '1'::int2 as isdepartment,
> departmentdescription as reportentitydescription,
> departmentsummary as reportentitysummary
> from department where isreportentity > 0;

> Oh here's the format of the reportentity table:
> reportentityid char(5) not null
> reportentityname varchar(110) not null
> reportentitydescription varchar(4000)
> reportentitysummary varchar(4000)
> isdepartment int2

It looks like the order of the columns in the table doesn't match the
order of the SELECT outputs. The 'AS' labels you're sticking on the
SELECT don't have anything to do with how the system will match things
up. If you want to write the column values in the select in an order
different than they're declared in the table, you must do

insert into reportentity (reportentityid, reportentityname, isdepartment,
...) select 'D0'|| ...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-02-20 21:15:25 Re: Re: Printing PostgreSQL reports
Previous Message Tom Lane 2001-02-20 21:08:10 Re: user meta (to the database, at least) information