pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHelper aggregate function
3+ messages / 3 participants
[nested] [flat]
* Helper aggregate function
@ 2008-02-03 11:44 sergey kapustin <kapustin.sergey@gmail.com>
2008-02-03 18:58 ` Re: Helper aggregate function Robins Tharakan <tharakan@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: sergey kapustin @ 2008-02-03 11:44 UTC (permalink / raw)
To: pgsql-sql
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!
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Helper aggregate function
2008-02-03 11:44 Helper aggregate function sergey kapustin <kapustin.sergey@gmail.com>
@ 2008-02-03 18:58 ` Robins Tharakan <tharakan@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Robins Tharakan @ 2008-02-03 18:58 UTC (permalink / raw)
To: sergey kapustin <kapustin.sergey@gmail.com>; +Cc: pgsql-sql
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!
>
>
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Helper aggregate function
@ 2008-02-03 20:07 Christian Kindler <christian.kindler@gmx.net>
0 siblings, 0 replies; 3+ messages in thread
From: Christian Kindler @ 2008-02-03 20:07 UTC (permalink / raw)
To: robins@pobox.com; +Cc: sergey kapustin <kapustin.sergey@gmail.com>; pgsql-sql
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 <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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2008-02-03 20:07 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-02-03 11:44 Helper aggregate function sergey kapustin <kapustin.sergey@gmail.com>
2008-02-03 18:58 ` Robins Tharakan <tharakan@gmail.com>
2008-02-03 20:07 Re: Helper aggregate function Christian Kindler <christian.kindler@gmx.net>
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