pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rison, Stuart <srison@rvc.ac.uk>
To: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Two TIMESTAMPs in one pl/sql function
Date: Tue, 26 Nov 2002 13:54:20 -0000
Message-ID: <6BD8CE460CC6EE40B83DDFCED609F84BE140D9@cmnt4008.rvc.ac.uk> (raw)

Hi,

I'm trying to time a pl/sql function using a rougn and ready method,
basically: print a TIMESTAMP at the begining of the function, print a
TIMESTAMP at the end of the function.

So...:

CREATE OR REPLACE FUNCTION timer() RETURNS INTEGER AS '
DECLARE 

	timer1 TIMESTAMP;
	timer2 TIMESTAMP;
	num_operators INTEGER;

BEGIN
	
	timer1 := ''now''; -- As suggested in 23.4 of programmer guide 	
	RAISE NOTICE ''Start: %'', timer1;
	
	/* Some function which takes time.
	Here, a select from a pg catalogue */
	 
	SELECT INTO num_operators COUNT(*) FROM pg_operator;
	
	timer2 := ''now'';
	RAISE NOTICE ''End: %'', timer2;
	
	RETURN(num_operators);
	
END;' 
LANGUAGE 'plpgsql';

Gives me:

testdb2=# select timer();
NOTICE:  Start: 2002-11-26 13:40:14.116605+00
NOTICE:  End: 2002-11-26 13:40:14.116605+00
 timer
-------
   623
(1 row)

I've tried all sorts of variations but I hit one of two problems; either the
TIMESTAMP is fixed to the function compile time or, as above, the timer1 and
timer2 TIMESTAMPs are always identical.

Any help/pointers/suggestions appreciate... well of course a working
solution would be the best ;)

Cheers,

Stuart.



view thread (2+ messages)  latest in thread

Message-ID: <6BD8CE460CC6EE40B83DDFCED609F84BE140D9@cmnt4008.rvc.ac.uk>
Permalink:  ../6BD8CE460CC6EE40B83DDFCED609F84BE140D9@cmnt4008.rvc.ac.uk/
Also on:    postgresql.org/message-id/6BD8CE460CC6EE40B83DDFCED609F84BE140D9@cmnt4008.rvc.ac.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: srison@rvc.ac.uk
  Subject: Re: Two TIMESTAMPs in one pl/sql function
  In-Reply-To: <6BD8CE460CC6EE40B83DDFCED609F84BE140D9@cmnt4008.rvc.ac.uk>
  References: <6BD8CE460CC6EE40B83DDFCED609F84BE140D9@cmnt4008.rvc.ac.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox