pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedPopulating a Table
3+ messages / 2 participants
[nested] [flat]
* Populating a Table
@ 2000-10-29 18:14 Chris Fossenier <Chris@pcguru.com>
0 siblings, 0 replies; 3+ messages in thread
From: Chris Fossenier @ 2000-10-29 18:14 UTC (permalink / raw)
To: pgsql-admin
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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Populating a Table
@ 2000-10-30 02:42 pgsql-admin <pgsql-admin@fc.emc.com.ph>
0 siblings, 0 replies; 3+ messages in thread
From: pgsql-admin @ 2000-10-30 02:42 UTC (permalink / raw)
To: Chris@pcguru.com; +Cc: pgsql-admin
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.
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Populating a Table
@ 2000-10-30 04:41 Chris Fossenier <Chris@pcguru.com>
0 siblings, 0 replies; 3+ messages in thread
From: Chris Fossenier @ 2000-10-30 04:41 UTC (permalink / raw)
To: pgsql-admin@fc.emc.com.ph; 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@fc.emc.com.ph> 10/29/00 09:42PM >>>
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.
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-10-30 04:41 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-10-29 18:14 Populating a Table Chris Fossenier <Chris@pcguru.com>
2000-10-30 02:42 Re: Populating a Table pgsql-admin <pgsql-admin@fc.emc.com.ph>
2000-10-30 04:41 Re: Populating a Table Chris Fossenier <Chris@pcguru.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox