Re: How to update record in a specified order

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: How to update record in a specified order
Дата
Msg-id 200208091512.59239.josh@agliodbs.com
обсуждение исходный текст
Ответ на Re: How to update record in a specified order  (Jean-Luc Lachance <jllachan@nsd.ca>)
Список pgsql-sql
JLL,

So, you want to update a field with a NEXTVAL counter, but with the counter
ordered by another column?

If so, you will have to use a procedure.   Ordering your UPDATEs is not part
of SQL -- it requires a procedural element.   Here's a simple procedure (you
debug it):

CREATE PROCEDURE add_my_table_counter ()
RETURNS TEXT AS '
DECLARE v_rec RECORD;
BEGINWHILE v_rec IN SELECT * FROM my_table ORDER BY last_name LOOP    UPDATE my_table SET counter_field =
NEXTVAL(''my_sequence'')   WHERE my_table.id = v_rec.id;END LOOP;RETURN ''Done updating.''; 
END;'
LANGUAGE 'plpgsql';

--
-Josh BerkusAglio Database SolutionsSan Francisco



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

Предыдущее
От: "Adam Erickson"
Дата:
Сообщение: Re: retrieving all rows from a "tree" in one select - how ?
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: retrieving all rows from a "tree" in one select - how ?