Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 13C7F2E2EA0 for ; Sun, 3 Feb 2008 16:07:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 39043-01 for ; Sun, 3 Feb 2008 16:07:07 -0400 (AST) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id 239042E2E89 for ; Sun, 3 Feb 2008 16:07:06 -0400 (AST) Received: (qmail 12046 invoked by uid 0); 3 Feb 2008 20:07:05 -0000 Received: from 84.74.52.141 by www008.gmx.net with HTTP; Sun, 03 Feb 2008 21:07:05 +0100 (CET) Cc: sergey kapustin , pgsql-sql@postgresql.org Content-Type: text/plain; charset="iso-8859-1" Date: Sun, 03 Feb 2008 21:07:05 +0100 From: "Christian Kindler" Message-ID: <20080203200705.17830@gmx.net> MIME-Version: 1.0 Subject: Re: Helper aggregate function To: robins@pobox.com X-Authenticated: #27759442 X-Flags: 0001 X-Mailer: WWW-Mail 6100 (Global Message Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX1/wIcwFnB7w5fQhXRpD6ebCTFmpyITYEcDF5cK9w2 Ys7DLQAqfFusxSQrEDw6xgu5G/ZvtNjxlijg== Content-Transfer-Encoding: 8bit X-GMX-UID: 0CaQDr9BQEV/FmWlznRpoOFCNzg2NUK2 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.902 tagged_above=0 required=5 tests=BAYES_05=-1.11, FAKE_REPLY_C=2.012 X-Spam-Level: X-Archive-Number: 200802/10 X-Sequence-Number: 30101 hi in this case you have to use execute: >> select $1,count(*) from $2 group by $1 order by $1; execute into myResultSet 'select ' || $1 || ' from ' || $2 || ' group by ' || $1 || ' order by ' || $2; see plpgsql docs for detailed information christian On Sun, February 3, 2008 19:58, Robins Tharakan wrote: > 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! >> >> >> >> > -- Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger