Using the extract() function in plpgsql
От | Kristis Makris |
---|---|
Тема | Using the extract() function in plpgsql |
Дата | |
Msg-id | 200106201649.f5KGnoa95364@postgresql.org обсуждение исходный текст |
Ответы |
Re: Using the extract() function in plpgsql
|
Список | pgsql-sql |
Hello all, I'm using PostgreSQL 7.1.2 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66 I'm having trouble making use of the extract function in plpgsql. The examples in the documentation show that the function can be called in the following way: SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours'); Result: 442800 If the function is called in the above way through the psql client, then a result is retrieved. But how can the extract() be used in a plpgsql function without using the EXECUTE statement? Here's what I've been trying: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CREATE FUNCTION ACFTProduced(TIMESTAMP, TIMESTAMP, DECIMAL(9,1)) RETURNS DECIMAL(9,2) AS ' DECLARElFromDate ALIAS FOR $1;lToDate ALIAS FOR $2;lFlow ALIAS FOR $3;lACFTProduced NUMERIC;lDateInterval INTERVAL;lSecondsINT4;lExecStmt TEXT; BEGINlDateInterval = lToDate - lFromDate; lExecStmt = ''SELECT extract(epoch from interval '' || '''''''' || lDateInterval || '''''''' || '') INTO lSeconds''; ----I would like to execute the following statement----SELECT extract(epoch from interval lDateInterval)--INTO lDays;-- RAISE NOTICE ''The difference interval is: %'', lDateInterval;RAISE NOTICE ''The seconds are: %'', lSeconds;RAISE NOTICE''The execStmt is: %'', lExecStmt; EXECUTE lExecStmt; RETURN lACFTProduced; END; ' LANGUAGE 'plpgsql'; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ If the function is called: test=# select acftproduced('2001-04-18 16:55:11-07', current_timestamp, 4.5); NOTICE: The difference interval is: 62 days 16:39:07 NOTICE: The seconds are: <NULL> NOTICE: The execStmt is: SELECT extract(epoch from interval '62 days 16:39:07') INTO lSeconds ERROR: EXECUTE of SELECT ... INTO is not implemented yet Is there any other way the extract() can be called? Thanks for any help -Kristis
В списке pgsql-sql по дате отправления: