Re: Upsert Functionality using CTEs

From: Tim Uckun <timuckun(at)gmail(dot)com>
To: Geoff Winkless <pgsqlgeneral(at)geoff(dot)dj>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Upsert Functionality using CTEs
Date: 2013-02-11 11:08:31
Message-ID: CAGuHJrOkyi=VZwD_rqzSUGagNxgT4FQcE3=uv2yt=TahdA2CnQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
>
> I read it that he has multiple sales from the same person? In which case
> pretending that the two sales were from different people isn't the correct
> result at all.

Actually it turns out that both cases exist.

>
> I may be missing the point of the query, but wasn't it to add an entry for
> each email address and (if it already exists in people) to update the
> firstname field to match the firstname in the order?

Yes. Basically the sales table is denormalized and I need to create or
update normalized tables from it. As you have pointed out the
difficult scenario is when the same person has multiple sales.

> Given that the results will be returned in random order I would just change
> the "nd" query to SELECT DISTINCT ON (email) , but like I said I may be
> missing the point.

I think in this case I am probably going to have go through the
records one at a time. I run into the same issues with other columns
such as products.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2013-02-11 14:03:58 fascinating article on postgresql mailing lists
Previous Message Geoff Winkless 2013-02-11 10:45:48 Re: Upsert Functionality using CTEs