Received: from datasoft.com (maniac.datasoft.com [63.228.155.187]) by postgresql.org (8.11.3/8.11.1) with SMTP id f5KGnoa95364 for ; Wed, 20 Jun 2001 12:49:50 -0400 (EDT) (envelope-from kristis.makris@datasoft.com) Message-Id: <200106201649.f5KGnoa95364@postgresql.org> Received: (qmail 25608 invoked from network); 20 Jun 2001 16:49:48 -0000 Received: from dsco-user.datasoft.com (HELO leonidas.corp.datasoft.com) (63.228.155.190) by maniac.datasoft.com with SMTP; 20 Jun 2001 16:49:48 -0000 Subject: Using the extract() function in plpgsql From: Kristis Makris To: pgsql-sql@postgresql.org Content-Type: text/plain X-Mailer: Evolution (0.9/+cvs.2001.03.14.20.47 - Preview Release) Date: 20 Jun 2001 09:49:43 -0700 Mime-Version: 1.0 X-Archive-Number: 200106/320 X-Sequence-Number: 3594 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 ' DECLARE lFromDate ALIAS FOR $1; lToDate ALIAS FOR $2; lFlow ALIAS FOR $3; lACFTProduced NUMERIC; lDateInterval INTERVAL; lSeconds INT4; lExecStmt TEXT; BEGIN lDateInterval = 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: 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