Re: Initialize the User-defined Aggregate in ECPG

Lists: Postg토토 사이트 순위SQL
From: Chengjie Qin <cqin3(at)ucmerced(dot)edu>
To: <pgsql-in-general(at)postgresql(dot)org>
Subject: Initialize the User-defined Aggregate in ECPG
Date: 2012-03-20 00:07:53
Message-ID: 8aef23d94f9dfa84625ece53b3ac53c9@mail2.ucmerced.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-in-general

Hi all,

I'm using the embedded SQL in C to create the User-Defined
Aggregate(UDA).
The command is :
CREATE AGGREGATE aggname( sfunc=kmeans,
stype=double precision[],
finalfunc=kmeansfinal,
INITCOND='{1,2,3}');

Since I need to do the aggregation in multiple rounds. I need to
initialize
the INITCOND using the execution result of last execution
(aggregation.)
Any one can tell me how can I initialize the INITCOND using host
variables
instead of hard code the INITCOND?

Thanks.

Jay


From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: Chengjie Qin <cqin3(at)ucmerced(dot)edu>
Cc: pgsql-in-general(at)postgresql(dot)org
Subject: Re: Initialize the User-defined Aggregate in ECPG
Date: 2012-03-20 04:06:13
Message-ID: CAFjFpRekTBeQLYdJGabBxhxNKiMORtf19coXRxZy4FxuuqR58Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-in-general

On Tue, Mar 20, 2012 at 5:37 AM, Chengjie Qin <cqin3(at)ucmerced(dot)edu> wrote:

> Hi all,
>
> I'm using the embedded SQL in C to create the User-Defined Aggregate(UDA).
> The command is :
> CREATE AGGREGATE aggname( sfunc=kmeans,
> stype=double precision[],
> finalfunc=kmeansfinal,
> INITCOND='{1,2,3}');
>
> Since I need to do the aggregation in multiple rounds. I need to initialize
> the INITCOND using the execution result of last execution (aggregation.)
> Any one can tell me how can I initialize the INITCOND using host variables
> instead of hard code the INITCOND?
>

There is no straight forward way to have 'variable' initial condition.
According to
http://www.postgresql.org/docs/9.1/static/sql-createaggregate.html, initial
condition can be a constant string acceptable by state_data_type's in
function. You might be able to achieve what you want by changing sfunc().
Set initial condition as null, and inside sfunc(), i.e. state transition
function, if you see NULL initial condition, pull the initial condition
from the database appropriately. But, this is the last resort. Why do you
need to have variable initial condition? Can you please elaborate the
problem you are solving, there might be simpler ways to handle this.

--
Best Wishes,
Ashutosh Bapat
EntepriseDB Corporation
The Enterprise Postgres Company


From: Pavan Deolasee <pavan(dot)deolasee(at)gmail(dot)com>
To: Chengjie Qin <cqin3(at)ucmerced(dot)edu>
Cc: pgsql-in-general(at)postgresql(dot)org
Subject: Re: Initialize the User-defined Aggregate in ECPG
Date: 2012-03-20 08:13:51
Message-ID: CABOikdNUKginZcbgbMuoWjVYbAvHOBRw-Z+B7QPNDXTDpqvgHg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg토토 사이트 순위SQL

On Tue, Mar 20, 2012 at 12:07 AM, Chengjie Qin <cqin3(at)ucmerced(dot)edu> wrote:

> Hi all,
>
> I'm using the embedded SQL in C to create the User-Defined Aggregate(UDA).
> The command is :
> CREATE AGGREGATE aggname( sfunc=kmeans,
> stype=double precision[],
> finalfunc=kmeansfinal,
> INITCOND='{1,2,3}');
>
> Since I need to do the aggregation in multiple rounds. I need to initialize
> the INITCOND using the execution result of last execution (aggregation.)
> Any one can tell me how can I initialize the INITCOND using host variables
> instead of hard code the INITCOND?
>
>
This list is for PostgreSQL users from India and is not very active. If you
would like to reach out to a wider audience, I will suggest you to post
your queries to pgsql-general(at)postgresql(dot)org(dot)

Thanks,
Pavan