Re: Update field to a column from another table

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Charles Clavadetscher <clavadetscher(at)swisspug(dot)org>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Update field to a column from another table
Date: 2016-04-21 20:56:59
Message-ID: 57193E9B.5060808@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/21/2016 11:52 AM, drum(dot)lucas(at)gmail(dot)com wrote:
> So when I run:
>
> UPDATE ja_jobs t2
> SET time_job = t1.time_job
> FROM junk.ja_test t1
> WHERE t2.id <http://t2.id> = t1.id <http://t1.id>
> AND t2.time_job IS DISTINCT FROM t1.time_job;
>
>
> I get:
>
> UPDATE 2202
>
> So I check the data by doing:
>
> select * FROM public.ja_jobs WHERE id = 14574527
>
>
> And the "time_job" field is null....

First idea:

Are you doing this in two different sessions at the same time, so
something like this?:

Session 1
BEGIN;
UPDATE ja_jobs t2
SET time_job = t1.time_job
FROM junk.ja_test t1
WHERE t2.id = t1.id
AND t2.time_job IS DISTINCT FROM t1.time_job;

Session 2
select * FROM public.ja_jobs WHERE id = 14574527

Where Session 2 is not seeing the UPDATE in Session 1 because the
transaction has not been COMMITed.

Second idea:

Does id = 14574527 meet the criteria AND t2.time_job IS DISTINCT FROM
t1.time_job?

>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gavin Flower 2016-04-21 21:27:34 Re: disable ipv6?
Previous Message John McKown 2016-04-21 20:56:04 Re: Proper relational database?