Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E77732E259B for ; Sun, 3 Feb 2008 14:58:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 90030-02 for ; Sun, 3 Feb 2008 14:57:59 -0400 (AST) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.158]) by postgresql.org (Postfix) with ESMTP id A92312E1E2F for ; Sun, 3 Feb 2008 14:58:01 -0400 (AST) Received: by fg-out-1718.google.com with SMTP id 22so1815469fge.23 for ; Sun, 03 Feb 2008 10:58:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=k2FAUtuHwrWvZMMBhkTuNqxc/l9HwZuDHez/2CM90CM=; b=yIGxdlZYN+Ip6wDAo3vek9ts38eYq/dLVMedDin8UH1cMEXItuzkXpsMZBU4C4LyclG69fbHGUiUbg44gUL2sRdipNGZpk8bDCsArR3zspVIqbm00349MQf8X9FXvKnDOmyiKVYbNhTbiFl585t4P83eqCnhkbhgMy1D4JYiWN8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references; b=dTllzzm8vvlQuzKwYk43/s8UlKrE3j3nKqYxSCSGg+1Ry2PRzLooDNEHXIStksgjjrlog2BNcudNZWGY1qd8yWg6cOGL+b0o3W6PbCkS1klCUSXJzah93kPrI7AAGc54ZNEY3ddDNpaQRUBLLwmijDP1M0HYx27klR1/vGQWKiY= Received: by 10.82.182.1 with SMTP id e1mr11319308buf.27.1202065080334; Sun, 03 Feb 2008 10:58:00 -0800 (PST) Received: by 10.82.113.9 with HTTP; Sun, 3 Feb 2008 10:58:00 -0800 (PST) Message-ID: <36af4bed0802031058j4ce4be26p111d0071bf31d5a0@mail.gmail.com> Date: Mon, 4 Feb 2008 00:28:00 +0530 From: "Robins Tharakan" Reply-To: robins@pobox.com To: "sergey kapustin" Subject: Re: Helper aggregate function Cc: pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2217_16254916.1202065080327" References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/9 X-Sequence-Number: 30100 ------=_Part_2217_16254916.1202065080327 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Please correct me if I am wrong, but as the last few lines of the first section in the given document says, you can use $n only for values and not for identifiers. http://www.postgresql.org/docs/8.3/static/xfunc-sql.html And one more thing, may be you would want to use a user-defined return type instead of void for this function. *Robins* On Feb 3, 2008 5:14 PM, sergey kapustin wrote: > Hello! > Can anyone tell me how i do this properly? > > create or replace function agg(varchar,varchar) returns void as $func$ > select $1,count(*) from $2 group by $1 order by $1; > $func$ > Language SQL; > > Right now this wives me "ERROR: syntax error at or near "$2" at character > 97 > select $1,count(*) from $2 group by $1 order by $1;" > > Thank you! > > > > ------=_Part_2217_16254916.1202065080327 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Please correct me if I am wrong, but as the last few lines of the first section in the given document says, you can use $n only for values and not for identifiers.

http://www.postgresql.org/docs/8.3/static/xfunc-sql.html

And one more thing, may be you would want to use a user-defined return type instead of void for this function.

Robins

On Feb 3, 2008 5:14 PM, sergey kapustin <kapustin.sergey@gmail.com> wrote:
Hello!
Can anyone tell me how i do this properly?

create or replace function agg(varchar,varchar) returns void as $func$
        select $1,count(*) from $2 group by $1 order by $1;
$func$
Language SQL;

Right now this wives me "ERROR:  syntax error at or near "$2" at character 97
select $1,count(*) from $2 group by $1 order by $1;"

Thank you!




------=_Part_2217_16254916.1202065080327--