Functions in Postgre

Поиск
Список
Период
Сортировка
От Uro Gruber
Тема Functions in Postgre
Дата
Msg-id 145447603700.20001228002015@sir-mag.com
обсуждение исходный текст
Список pgsql-general
Hi!

I have 2 questions.

1. I want to store some data in database (8 different fields) and then
check some other thig and if something is ok i wan't to update some
data. I think i have to use function for this, because i don't want to
send so many queries over the net.
But now i'm confused. Is it ok if i use function with like 8 arguments
or is it better to insert data with normal INSERT query and then use
triger on INSERT wich calls some function to do all the work.
I would like someone to tell me more about this. Because document are
realy bad. Is it some great documents or book out in the net or book
store.


2. I have 3 SELECT queries


- SELECT id,name FROM users WHERE id = '40';
- SELECT id FROM users WHERE id > '40' ORDER BY id ASC LIMIT 1;
- SELECT id FROM users WHERE id < '40' ORDER BY id DESC LIMIT 1;

Now i want to create a function who wil execute al tree.
something like this

CREATE FUNCTION get_user(int4) RETURNS ?? AS '

..
..
..

' LANGUAGE = 'plpgsql'

I want output like this when i call this function ( SELECT
get_user('40');

id     name    idprev   idnext
------------------------------
40     user1     35       42


id's are not one by one but its generated and stored as 23characters
(this 40 is just an example.)

What i want to know is how can i write that function and What should i
put after RETURNS and then how to return data.


Thanks for help
--

Uros



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

Предыдущее
От: Mike Castle
Дата:
Сообщение: Re: LD_LIBRARY_PATH
Следующее
От: "Rick Vlahov"
Дата:
Сообщение: PostgreSQL on AIX