Re: Update ordered

Поиск
Список
Период
Сортировка
От Achilleas Mantzios
Тема Re: Update ordered
Дата
Msg-id 52E67FF6.9060806@matrix.gatewaynet.com
обсуждение исходный текст
Ответ на Update ordered  (Andreas Joseph Krogh <andreak@officenet.no>)
Список pgsql-sql
On 27/01/2014 16:36, Andreas Joseph Krogh wrote:
> Hi all.
> I want an UPDATE query to update my project's project_number in chronological order (according to the project's
"created"-column)and tried this:
 
> with upd as(
>     select id from project order by created asc
> ) update project p set project_number = get_next_project_number() from upd where upd.id = p.id;
> However, the olders project doesn't get the smalles project_number.

I think that makes sense. When you UPDATE ... FROM an another relation, nothing is guaranteed
about the order of the from_list join. Therefore "order by created asc" in your CTE is not gonna
achieve much.

Your better write this as a procedure. (as you have already suggested)

> Any idea how to achive this?
> Thanks.
> --
> Andreas Joseph Krogh <andreak@officenet.no>      mob: +47 909 56 963
> Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
> Public key: http://home.officenet.no/~andreak/public_key.asc


-- 
Achilleas Mantzios
Head of IT DEV
IT DEPT
Dynacom Tankers Mgmt




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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Update ordered
Следующее
От: ssylla
Дата:
Сообщение: Re: Trigger function - variable for schema name [SOLVED]