Re: Separating data sets in a table

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Andreas Tille <tillea(at)rki(dot)de>
Cc: PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Separating data sets in a table
Date: 2002-08-26 10:31:38
Message-ID: 1030357898.22926.7.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 2002-08-26 at 10:46, Andreas Tille wrote:
> On 26 Aug 2002, Oliver Elphick wrote:
>
> > Select from the temporary table all items that satisfy the
> > constraints, insert them into the real table and delete them from
> > the temporary table:
> >
> > BEGIN;
> > INSERT INTO tablename (SELECT * FROM temptable WHERE ...);
> > DELETE FROM temptable WHERE ...;
> > COMMIT;
> >
> > All good data should now be in place. The temporary table should
> > now contain only those items that do not satisfy the constraints for
> > the real table.
> This was in my first atempt here.
> The problem I have is that I need a JOIN to a further table and
> I've got errors from the parser which let me guess that joins are not
> allowed in INSERT statements ... at least I do not know how to do it
> right if it should be possible.

A natural join seems to work fine:

bray=# insert into junk (select b.* from batch as b, product as p
where b.product = p.id and p.eancode is not null);
INSERT 0 7552

I don't have any earlier messages from this thread; what was the syntax
you were trying to use?

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Seeing then that all these things shall be dissolved,
what manner of persons ought ye to be? You ought to
live holy and godly lives as you look forward to the
day of God and speed its coming."
II Peter 3:11,12

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jiaqing Wang 2002-08-26 14:56:51 Re: weird situation, BUG or I'm not doing it right
Previous Message Andreas Tille 2002-08-26 09:46:12 Re: Separating data sets in a table