From: | Andreas Tille <tillea(at)rki(dot)de> |
---|---|
To: | PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org> |
Subject: | Separating data sets in a table |
Date: | 2002-08-22 09:46:24 |
Message-ID: | Pine.LNX.4.44.0208221126490.1478-100000@wr-linux02.rki.ivbb.bund.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello,
I want to solve the following problem:
CREATE TABLE Ref ( Id int ) ;
CREATE TABLE Import ( Id int,
Other varchar(42),
Flag int,
Ts timestamp ) ;
CREATE TABLE Data ( Id int,
Other varchar(42) ) ;
The table Import will be filled by a COPY FROM statement and contains
no checks for referential integrity. The columns Id and Other have to
be moved to the table Data if the table Ref contains the Id. If not
Flag should get a certain value that something went wrong. Moreover
Import should only contain one representation of a dataset with equal
Id and Other column and I would like to store the newest one (this
is the reason for the timestamp).
I tried to do the following approach:
CREATE LOCAL TEMPORARY TABLE ImportOK () INHERITS (Import) ;
INSERT INTO ImportOK SELECT * FROM Import i
INNER JOIN Ref r ON i.Id = r.Id;
DELETE FROM Import WHERE Id IN (SELECT Id FROM ImportOK) ;
The idea was that the latest statement should get rid of all valid
data sets from Import. The valid datasets now could be moved to Data
and I could afterwards check Import for duplicated data sets.
Unfortunately the latest statement is so terribly slow that I can't
imagine that there is a better way to do this.
It seems like a very beginner question but I have no real clue how
to do this right. Probably the solution has to be done completely
different.
Thanks for your patience
Andreas.
From | Date | Subject | |
---|---|---|---|
Next Message | Lucas Brasilino | 2002-08-22 11:46:07 | Re: Problem with timestamp field/time function.. (upgrading |
Previous Message | Philip Rudling | 2002-08-22 09:03:41 | sql statement to give functionality of \d tablename? |