Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 4139C475AD0 for ; Thu, 6 Jun 2002 08:22:46 -0400 (EDT) Received: from smtp014.mail.yahoo.com (smtp014.mail.yahoo.com [216.136.173.58]) by postgresql.org (Postfix) with SMTP id 5582F4759DF for ; Thu, 6 Jun 2002 08:22:44 -0400 (EDT) Received: from unknown (HELO saturn.janwieck.net) (janwieck@192.233.92.205 with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 6 Jun 2002 12:22:47 -0000 Received: (from wieck@localhost) by saturn.janwieck.net (8.11.2/8.11.2) id g56CKtO26245; Thu, 6 Jun 2002 08:20:55 -0400 From: Jan Wieck Message-Id: <200206061220.g56CKtO26245@saturn.janwieck.net> Subject: Re: extract and variables in PL/pgSQL In-Reply-To: <20020605182054.GA1307@cc.usu.edu> from Roberto Mello at "Jun 5, 2002 12:20:54 pm" To: Roberto Mello Date: Thu, 6 Jun 2002 08:20:55 -0400 (EDT) Cc: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200206/52 X-Sequence-Number: 8017 Roberto Mello wrote: > Hi, > > Someone in another list asked about this function. I'm not sure why it > doesn't work. What am I missing? > > CREATE FUNCTION zastras(timestamp) RETURNS integer AS ' > declare > w_temp1 alias for $1; > w_result integer; > begin > SELECT INTO w_result EXTRACT(epoch from timestamp w_temp1); > return w_result; > > end; > ' language 'plpgsql'; > > NOTICE: Error occurred while executing PL/pgSQL function zastras > NOTICE: line 5 at select into variables First you're missing the error message, which should read something like ERROR: parser: parse error at or near "$1" Doesn't help much here, but it is usually a good idea to include error messages in reports like this. I'm not 100% sure, but it seems that the PostgreSQL main parser doesn't support parameters in the place of this "timestamp" expression construct. It works if you leave out the keyword "timestamp" writing SELECT INTO w_result EXTRACT(epoch from w_temp1); because the variable w_temp1 is known to be of type timestamp already and therefore the a_expr node on the right hand side of from is valid. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #