EXPLAIN запроса в pg-функции

partizan

Новичок
EXPLAIN запроса в pg-функции

Ф-я на pgSQL выполняет некоторый запрос, хранящийся в переменной q.
После этого я хочу, чтоб ф-я занесла в отдельную таблицу текст этого запроса, время выполнения и explain запроса.

Как мен получить explain запроса внутри ф-и.

По идее нажо написать:

PHP:
exp:='';
q:='EXPLAIN ' || q;

FOR r IN EXECUTE  q LOOP
	exp:= exp || r.some_field;
END LOOP;
(переменная r типа record)


Проблема в том, что результат запроса "EXPLAIN ..." возвращается ввиде:
PHP:
Array ( [QUERY PLAN] => Seq Scan on users (cost=0.00..1.23 rows=23 width=560) )
Т.е. поле называется QUERY PLAN - через пробел.

Проьовал с подчеркиванием, и слитно - не работает
 

partizan

Новичок
Работает! Спасибо

-~{}~ 04.08.06 18:04:

Еще одна проблема - как посчитать время выполнения? Ф-я now() возвращает один и тот же результат внутри ф-и
 

Clubber

Новичок
Within a stored routine or trigger, NOW() returns a constant time that indicates the time at which the routine or triggering statement began to execute. This differs from the behavior for SYSDATE().
© MySQL Manual.
В постгресе, думаю, так же.
 

Sad Spirit

мизантроп (Старожил PHPClub)
Команда форума
Автор оригинала: Clubber
В постгресе, думаю, так же.
Почти так же:
It is important to know that CURRENT_TIMESTAMP and related functions return the start time of the current transaction; their values do not change during the transaction. This is considered a feature: the intent is to allow a single transaction to have a consistent notion of the "current" time, so that multiple modifications within the same transaction bear the same time stamp.

There is also the function timeofday() which returns the wall-clock time and advances during transactions. For historical reasons timeofday() returns a text string rather than a timestamp value:
 
Сверху