Re: INOUT parameters in procedures

Поиск
Список
Период
Сортировка
От Douglas Doole
Тема Re: INOUT parameters in procedures
Дата
Msg-id CADE5jYLZyF1WAan81Jxoi8jPNRte08zxZfDY_uuxsnQVmigTPQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: INOUT parameters in procedures  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-hackers
At the top-level, it's even more dubious.  In DB2, apparently you write

CALL foo(123, ?);

with a literal ? for the OUT parameters.

That's not actually as scary as it seems.

DB2 has two cases where you can use a ? like that:

1) In CLP (DB2's equivalent to psql)

DB2 draws a distinct line between procedures and functions, and you have to invoke procedures with CALL FOO(...). Since CLP doesn't support variables (and SQL variables didn't exist in DB2 when the CALL statement was introduced), they needed a way to say "there's an output parameter here" so they settled on using ? as the placeholder. (? was chosen because it ties nicely into the next point.)

2) In dynamic SQL

DB2 has traditionally used ? as a parameter marker (placeholder for a variable) in dynamic SQL. So the usage would look something like:

DECLARE res INTEGER;
DECLARE text VARCHAR(50);

SET text = 'CALL foo(123, ?)';
PREPARE stmt FROM text;
EXECUTE stmt INTO res; -- This invokes the statement and maps the ? into the variable "res"

If you didn't need/want to use dynamic SQL, then you could have simply written:

CALL foo(123, res);

- Doug Doole
Salesforce

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

Предыдущее
От: Fujii Masao
Дата:
Сообщение: Re: [bug fix] pg_rewind takes long time because it mistakenly copiesdata files
Следующее
От: Fujii Masao
Дата:
Сообщение: Re: [HACKERS] Creating backup history files for backups taken from standbys