pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brook Milligan <brook@trillium.NMSU.Edu>
To: pgsql-sql@postgresql.org
Subject: creating tables with distinct tuples
Date: Thu, 21 May 1998 17:03:08 -0600 (MDT)
Message-ID: <199805212303.RAA07634@trillium.nmsu.edu> (raw)

I am trying to create one table from another in such a way that it
contains only a subset of distinct rows from the first.  I load data
into the first table, then 'insert into table select distinct ...' and
expected to find a bunch of distinct rows.  No such luck for my data
set (though it works with other test data sets)!  Am I missing
something obvious about how to do this?  An outline of what I'm doing
follows, but I've left out the data.  So far I cannot make a small
data set exhibit the problem.

Any help greatly appreciated!

Cheers,
Brook

---------------------------------------------------------------------------
drop table leaf_surveys;
create table leaf_surveys
(
 leaf_survey_id	int4	primary key		default nextval ('leaf_survey_id_sequence'),
 user		name				default current_user,
 time		datetime			default datetime (now ()),

 plot_id	int4	not null,		-- references plots.plot_id
 id		int	not null,
 plant_number	int,
 tag		int4,

 survey_date	text,
 color		char(1),
 status		int,
 leaf_number	int,
 stalk_number	int,

 unique (plot_id, id, survey_date)
);
---------------------------------------------------------------------------
insert into leaf_surveys (plot_id, id, plant_number, tag, survey_date, color, status, leaf_number, stalk_number)
	 values ('903', '1', '', '82', '05/24/95', '', '2', '7', '1');
insert into leaf_surveys (plot_id, id, plant_number, tag, survey_date, color, status, leaf_number, stalk_number)
	 values ('903', '2', '', '97', '05/24/95', '', '2', '7', '');
insert into leaf_surveys (plot_id, id, plant_number, tag, survey_date, color, status, leaf_number, stalk_number)
	 values ('903', '4', '', '148', '05/24/95', '', '2', '12', '0');
-- lots more omitted
---------------------------------------------------------------------------
drop table plants;
create table plants
(
 plant_id	int4	primary key		default nextval ('plant_id_sequence'),
 user		name				default current_user,
 time		datetime			default datetime (now ()),

 plot_id	int4	not null,		-- references plots.plot_id
 id		int4,
 tag		int4
-- unique (plot_id, id, tag)
);
---------------------------------------------------------------------------
select distinct plot_id, id, tag from leaf_surveys; -- yields a list of distinct rows
insert into plants (plot_id, id, tag) select distinct plot_id, id, tag from leaf_surveys;
select * from plants; -- yields a list with duplicate rows



Message-ID: <199805212303.RAA07634@trillium.nmsu.edu>
Permalink:  ../199805212303.RAA07634@trillium.nmsu.edu/
Also on:    postgresql.org/message-id/199805212303.RAA07634@trillium.nmsu.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: brook@trillium.NMSU.Edu
  Subject: Re: creating tables with distinct tuples
  In-Reply-To: <199805212303.RAA07634@trillium.nmsu.edu>
  References: <199805212303.RAA07634@trillium.nmsu.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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