self-referential UPDATE problem on 7.4

Поиск
Список
Период
Сортировка
От Karsten Hilbert
Тема self-referential UPDATE problem on 7.4
Дата
Msg-id 20070104151856.GC3969@merkur.hilbert.loc
обсуждение исходный текст
Ответы Re: self-referential UPDATE problem on 7.4  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hello !

I am trying to run this query in psql:

update clin.episode
set fk_patient = clin.health_issue.fk_patient
from clin.health_issue
where
    clin.episode.fk_patient is NULL and
    clin.episode.fk_health_issue = clin.health_issue.pk;

It returns "UPDATE 2" which is what I expect from the data.
However, the rows in question are not actually updated.

What I am trying to do:

- clin.episode has a nullable foreign key fk_health_issue to clin.health_issue.pk
- clin.health_issue has a not-nullable fk_patient
- clin.episode also has an fk_patient which is nullable

I want to transfer the value of clin.health_issue.fk_patient
to clin.episode.fk_patient to those clin.episodes for which
fk_patient is NULL.

I'm sure I am doing something wrong in a fairly basic way.

I tried with a subselect, too, but get the same result:

update clin.episode
set fk_patient = (
    select fk_patient from clin.health_issue chi where chi.pk=clin.episode.fk_health_issue
)
where fk_patient is NULL;

This is on 7.4.14 on Debian/Etch.

Thanks,
Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

В списке pgsql-general по дате отправления:

Предыдущее
От: "Ravindra Jaju"
Дата:
Сообщение: Re: How to use the SQL parser subsystem
Следующее
От: "Ravindra Jaju"
Дата:
Сообщение: Re: How to use the SQL parser subsystem