Skip site navigation (1) Skip section navigation (2)

Re: [NOVICE] Need help with a query

From: scorpdaddy(at)hotmail(dot)com <scorpdaddy(at)hotmail(dot)com>
To: A B <gentosaker(at)gmail(dot)com>,pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] Need help with a query
Date: 2010-10-26 10:24:51
Message-ID: BLU0-SMTP924358D0FD46F6767365DCE420@phx.gbl (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Is it necessary that this is a table? Because it seems a lot like a view of the same data actually. CREATE VIEW ...

The expected UPDATE query for a table can be problematic. I have a similar issue in 1 of my DB's.  New records - new x, y - get written to bar and do not yet have a corresponding x, y record in foo.  So when the UPDATE runs it ignores the new records.  One can have an after insert trigger to keep foo up to date with bar. But such machinations arise because foo is only a view of the same data in bar. 

----- Reply message -----
From: "A B" <gentosaker(at)gmail(dot)com>
Date: Tue, Oct 26, 2010 6:16 am
Subject: [NOVICE] Need help with a query
To: <pgsql-novice(at)postgresql(dot)org>


I'm having a problem with  a probably very simple query.
I need to update a table
foo (x int, y int, last_seen timestamp, unique(x,y));

where the values should be taken from a larger table
bar( x int, y int, seen timestamp);
where each x,y combination occurs several times, and the value in
foo.last_seen should be the value max(seen) for each pair of x,y.
Notice! All combinations of x,y in bar are also in foo, but not the
other way around.

So how do I write a query for this?
Thanks in advance.


pgsql-novice by date

Next:From: Rainer RaspelDate: 2010-10-26 10:49:55
Subject: PSQL9 installation for WIN
Previous:From: Oliveiros d'Azevedo CristinaDate: 2010-10-26 09:39:19
Subject: Re: Need help with a query

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group