Re: increment Rows in an SQL Result Set postgresql

Поиск
Список
Период
Сортировка
От Craig A. James
Тема Re: increment Rows in an SQL Result Set postgresql
Дата
Msg-id 44B92578.1060705@modgraph-usa.com
обсуждение исходный текст
Ответ на increment Rows in an SQL Result Set postgresql  (Hassan Adekoya <hechy_man@yahoo.com>)
Ответы Re: increment Rows in an SQL Result Set postgresql  (Hassan <hechy_man@yahoo.com>)
Список pgsql-performance
Hassan,

> 1. I have a function that given two parameter produces an arbitrary id, and
> text. However arbitrary the id and text are, they are in certain order. i.e. it
> is imperative that whatever processing I do, the order is preserved.

What type of function is this?  Did you write it in C?  An SQL procedure?

If the function is written in C, you can create a static local variable which you increment every time you call your
function,and which you return along with your other two values.  As long as your client is connected to the back-end
server,you're guaranteed that it's a single process, and it's not multi-threaded, so this is a safe approach.  However,
notethat if you disconnect and reconnect, your counter will be reset to zero. 

If your function is written in a different language or is a procedure, you might create a sequence that your function
canquery. 

The trick is that it is the function itself that must return the incremented value, i.e. you must return three, not
two,values from your function.  That way, you're not relying on any specific features of the planner, so your three
valueswill stick together. 

Craig

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

Предыдущее
От: Hassan Adekoya
Дата:
Сообщение: increment Rows in an SQL Result Set postgresql
Следующее
От: Hassan
Дата:
Сообщение: Re: increment Rows in an SQL Result Set postgresql