Re: Populating a Table

From: "Chris Fossenier" <Chris(at)pcguru(dot)com>
To: <pgsql-admin(at)fc(dot)emc(dot)com(dot)ph>, <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Populating a Table
Date: 2000-10-30 04:41:21
Message-ID: s9fcb5aa.079@mail.pcguru.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hey Sherwin,

You da man!

Your statement worked great, I just had to put parentheses around key:

i.e.
DISTINCT ON (key)

Thank you very much.

Chris.

>>> "pgsql-admin" <pgsql-admin(at)fc(dot)emc(dot)com(dot)ph> 10/29/00 09:42PM >>>
try
INSERT INTO table2
SELECT DISTINCT ON key key, name, field1, field2
FROM table1;

sherwin

Chris(at)pcguru(dot)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.
>

Browse pgsql-admin by date

  From Date Subject
Next Message Dr. Hans-Christian Waldmann 2000-10-30 10:05:55
Previous Message pgsql-admin 2000-10-30 02:42:50 Re: Populating a Table