From: | Dmitriy Igrishin <dmitigr(at)gmail(dot)com> |
---|---|
To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Implementing replace function |
Date: | 2010-10-31 09:37:38 |
Message-ID: | AANLkTin9-RofbD2nLZxBxWTewsqcbvhwosvv2Lz-cHiH@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hey Alexander, Pavel
The solution like below should works IMO, but it does not.
insert into pref_users(id, first_name, last_name,
female, avatar, city, last_ip)
select $1, $2, $3, $4, $5, $6, $7
where not exists
(update pref_users set first_name = $2,
last_name = $3,
female = $4,
avatar = $5,
city = $6,
last_ip = $7
where id = $1
returning id);
BTW, I don't understand why it not possible to write query like this:
SELECT id FROM (UPDATE test SET nm = 'dima' WHERE id = 1 RETURNING id) AS
foo;
According to the doc (of UPDATE command) "The syntax of the RETURNING list
is identical to
that of the output list of SELECT).
With this syntax, the OPs goal can be implemented in SQL..
--
// Dmitriy.
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2010-10-31 09:44:20 | Re: Implementing replace function |
Previous Message | Pavel Stehule | 2010-10-31 09:12:38 | Re: Implementing replace function |