pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Eckermann <jeff_eckermann@yahoo.com>
To: Travis Hoyt <thoyt@npc.net>
To: pgsql-sql@postgresql.org
Subject: Re: function error
Date: Thu, 28 Mar 2002 07:35:25 -0800 (PST)
Message-ID: <20020328153525.78708.qmail@web20806.mail.yahoo.com> (raw)
In-Reply-To: <DBEMKMGOMJAGKAKEPPEGKEANDHAA.thoyt@npc.net>

If this is genuinely a copy of something in the
"PostgreSQL Developer's Handbook", then that book
could use some work.
1. You need "ALIAS FOR" in the DECLARE section
2. You need an explicit RETURN; i.e. write "RETURN
result;" before "END;"
3. Language is plpgsql, not sql (which doesn't allow
the constructions you are using).

If columns "systemid" and "time" are not of text type,
you will need to do some type casting for your
comparisons to work.  I believe "time" is a reserved
word anyway, so if that is the real name of the
column, you will need to double-quote it, which in the
function definition will need to be escaped:
'"time"', or \"time\".

--- Travis Hoyt <thoyt@npc.net> wrote:
> CREATE FUNCTION biwklyavg(text, text, text) RETURNS
> numeric AS '
>         DECLARE
>                 system          ALIAS $1;
>                 startdate       ALIAS $2;
>                 enddate         ALIAS $3;
>                 result          numeric;
> 
>         BEGIN
>                 result := (select (avg(usr) +
> avg(sys)) from sardata where
> systemid = system
>                         and time between startdate
> and enddate;
>         END;
> ' LANGUAGE 'sql';
> 
> Hello,
> 
> The fuction listed above gives the following error:
> 
> ERROR:  parser: parse error at or near "alias"
> 
> I'm running v7.2.  Any ideas?  I pulled this
> directly from the examples in
> the PostgreSQL Developer's Handbook.
> 
> Thanks,
> 
> Travis
> 

> ATTACHMENT part 2 application/x-pkcs7-signature
name=smime.p7s



__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/



view thread (14+ messages)  latest in thread

Message-ID: <20020328153525.78708.qmail@web20806.mail.yahoo.com>
Permalink:  ../20020328153525.78708.qmail@web20806.mail.yahoo.com/
Also on:    postgresql.org/message-id/20020328153525.78708.qmail@web20806.mail.yahoo.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jeff_eckermann@yahoo.com, thoyt@npc.net
  Subject: Re: function error
  In-Reply-To: <20020328153525.78708.qmail@web20806.mail.yahoo.com>

* 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