Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:54:34+00:00 2026-05-30T16:54:34+00:00

Problem description : I’m trying to define a pl/python aggregator that receives a set

  • 0

Problem description: I’m trying to define a pl/python aggregator that receives a set of rows and returns a set of rows, for every set of rows generated from a query. The input set of rows should be a group generated with the group by statement in a query. I’m trying to find my way through the syntax, but I’m having a hard time with that. pl/pgsql functions are welcome, but I’m afraid they may lack the expressive power to do this.

Context description: I have a table with three columns: ticker symbol, date and value. I’m trying to calculate the macd for each ticker symbol and date according to the values I have. I can group and sort the table by date, then all I would have to do is for each group calculate the value of the aggregator for that date according to the current value for each ticker and the previous value for the aggregator, which I guess I will store in SD, then all I have to return is a set of rows with that value, and possibly the ticker to make a join, but I think it should be possible to preserve the order and save the time of a join.

This is how the table would be created:

create table candles(ticker text, day date, value real,
  primary key (ticker, day));

Here you can find an example in Java (pseudocode-ish) that shows how the groups (group by day) should be processed after sorted by ticker. In Java these groups are represented as an ArrayList, since they are sorted by ticker, the same position corresponds to the same ticker (database is checked on generation so no records are missing) and since they are grouped by day every group has the values for the same day and the next day than the previous call.

PD: I’ve also added the code to calculate MACD in pl/pgsql but for this I order by ticker and day, I’d like to order by day and do all the calculations for all the tickers in a loop, because that should be more efficient, specially considering the final output has to be ordered by day to be consumed in this way.

If there is anything that is not completely clear please ask me, I’m trying to be clear and concise.

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:54:36+00:00Added an answer on May 30, 2026 at 4:54 pm

    Sorry if the description was confusing. I solved the problem I was facing by:

    1. creating arrays from the values I wanted to group by using a subquery. select array_agg(x) from y group by z order by v;
    2. creating a function that accepts the arrays, just by adding [] to the parameters description. And an aggregator for that function.
    3. using the aggregator and the subquery in the final query.

    It was fairly easy, but I didn’t know about the array type and all its possibilities. Sorry and thank you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Expanding this question on how I learnt to pass from problem description to code
SHORT DESCRIPTION OF PROBLEM: I want to set the text of a searchbar without
Ok, so here's the full description of the problem I'm having: I am trying
Below is the problem description and algorithm that I have written. Is there anything
Problem Description: Multi-player Game that works over the some kind of network, in game
Problem description: I have a POJO object, which is mapped from database. Which having
Problem Description I'm writing module for Android (JAVA) that use native code (C) .
The problem is to write the python that calculates the interest due on a
Problem Description I am writing a Java application that lets programmers query for page
Problem Description I have an abstract Paper class that contains common properties of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.