Received: from jennifer.emc.com.ph ([203.167.64.3]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id e9U2hE297649 for ; Sun, 29 Oct 2000 21:43:14 -0500 (EST) (envelope-from pgsql-admin@fc.emc.com.ph) Received: from fc.emc.com.ph (fc.emc.com.ph [208.232.224.197]) by jennifer.emc.com.ph (Postfix) with ESMTP id 2E9DBD72E; Mon, 30 Oct 2000 10:43:10 +0800 (PST) Message-id: Date: Mon, 30 Oct 2000 10:42:50 +0800 Subject: Re: Populating a Table To: Chris@pcguru.com Cc: pgsql-admin@postgresql.org From: "pgsql-admin" MIME-Version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Archive-Number: 200010/4 X-Sequence-Number: 4 try INSERT INTO table2 SELECT DISTINCT ON key key, name, field1, field2 FROM table1; sherwin Chris@pcguru.com writes: >Hello, > >I'm sure I'll be flagged as a moron for asking this question, so be it. > >I have some tables of info with no primary keys. As a result the field I >want to key on is repeated. My plan is to do a DISTINCT select from the >un-keyed table into another table that does have constraints. > >Here is what I thought would work: > >INSERT INTO table2 > SELECT DISTINCT(key), name, field1, field2 > FROM table1; > >When I issue this statement it tells me that you cannot put in duplicate >values into my key field. Why does it do that? If I issue the following >statement I get exactly what I want: > >SELECT DISTINCT(phone) from table1; > >Am I using the DISTINCT function incorrectly? Is it taking all of the >field and using them to create a distinct row? > >Any help would be appreciated. > >Chris. >