Lists: | pgsql-general |
---|
From: | Matthew Pugsley <matthew(dot)pugsley(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | update one table with another |
Date: | 2009-04-20 20:34:25 |
Message-ID: | 873251980904201334w1bb49ad4s5fdc9992fab1c09f@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
I've solved it.
I just used a subselect. Worked very quickly. I had a lot of trouble with
subqueries when I first started databases with MySQL. So I have been afraid
of them.
update entities
set customer_status = select(customer_status from entity_dimension_update
where entities.entity_id = entity_dimension_update.entity_id);
Worked almost instantly.
My apologies for the spam.
--
matthew(dot)pugsley(at)gmail(dot)com
From: | Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> |
---|---|
To: | Matthew Pugsley <matthew(dot)pugsley(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: update one table with another |
Date: | 2009-04-20 23:12:15 |
Message-ID: | 84643391-8BDB-4A36-A670-395B3C42A8E0@solfertje.student.utwente.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Apr 20, 2009, at 10:34 PM, Matthew Pugsley wrote:
> I've solved it.
>
> I just used a subselect. Worked very quickly. I had a lot of trouble
> with subqueries when I first started databases with MySQL. So I have
> been afraid of them.
>
> update entities
> set customer_status = select(customer_status from
> entity_dimension_update where entities.entity_id =
> entity_dimension_update.entity_id);
What a peculiar way to write a subquery, with the braces like that.
Normally you'd put the opening brace before the select statement, not
after it.
> Worked almost instantly.
Alternatively you could use UPDATE...FROM:
update entities
set customer_status = t2.customer_status
from entity_dimension_update as t2
where entity_id = t2.entity_id
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.
!DSPAM:737,49ed0151129747011493647!