Unix Technical Forum

Re: Helper aggregate function

This is a discussion on Re: Helper aggregate function within the pgsql Sql forums, part of the PostgreSQL category; --> hi in this case you have to use execute: >> select $1,count(*) from $2 group by $1 order by ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:00 PM
Christian Kindler
 
Posts: n/a
Default Re: Helper aggregate function

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/s...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!
>>
>>
>>
>>

>



--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:15 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com