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

  • SEARCH
  • Home
  • 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 732209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:06:54+00:00 2026-05-14T07:06:54+00:00

I am working in Postgres and I need to send in a full result

  • 0

I am working in Postgres and I need to send in a full result set with many rows and column into a stored procedure or a function. Is this possible? If so, where can I see resources for syntax?

OK this is how I have it set up without being able to send in a result set, it forces me to break out comparison logic and put it in two different spots, however my goal is to keep the actual finding the promotion logic in one place, which I have done here. This may change one day, the comparison logic is less likely to change, it is pretty standard.

Promotion Line Item Logic

-There will be triggers set on INSERT for the promo_objects, promo_buy_objects, and promo_get_objects tables, there will be an UPDATE trigger on the promo table.
-The trigger for the xrefs will call a stored procedure called set_best_product_promos that will decide which promotion is best for that object and it will then save to a new table:

promo_best_product_promos

promo_id,
object_id,
expiration_date

-The trigger for promo will call update_best_product_promos and will send in the promo_id and if active = true it will update the expiration date for that promo else it will delete all entries for that promo

The new table has been added to the promo.sql script, however the triggers and function can not be added until the function is written.

A script will run at midnight every night to delete the entries that have expired.
PSEUDO FOR cart code (application code)
Run the union query just as we are now shown_object_promotions (this gets all available promotions for the item)

Loop through results
  if buy_quantity > 0
        IF the quantity of the buy item in the cart is greater than or = the buy_quantity (I think c.active_items is the items in the cart)
          IF get_quantity > 0
            If the get item is in the cart AND it is the item sent into this function (I think c.active_items is the items in the cart) 
              run the get_best_product_promos function
              run comparison logic
          else
            run the get_best_product_promos function 
            run comparison logic

EDIT: So I guess I could dump this cart logic as a stored procedure as well, and then make one for the comparison logic, and boom its all in stored procedures and portable and generic?

PSEUDO FOR set_best_product_promos:

-You will send in the object_id and promo_id
-You will declare all of your variables
-Go ahead an query the end date of the promo
-You will then query the promo_best_product_promos table to see if an entry exists for this product

IF exists:
    RUN YOUR UNION QUERY accept this time you will have to explicitly say all the fields you want and what variables to select them into

    Then loop through your query
    LOOP
      run get_best_product_promos
      run comparison logic
    END LOOP

    Now take those variables you set in the crazy logic and update promo_best_product_promos
ELSE:
    insert the object_id, promo_id, and end date (expiration_date) into the promo_best_product_promos table

PSEUDO FOR get_best_product_promos:

If no buy and no get quantities
    If discount type = percent
      calculate value of the promotion for this item to compare later
      calculate the new price for the product and update the estimated unit price
    If discount type = dollar
      calculate value of the promotion for this item to compare later
      calculate the new price for the product and update the estimated unit price
    If discount type = price
      calculate value of the promotion for this item to compare later
      calculate the new price for the product and update the estimated unit price
    If discount amount = Free
      do nothing 
      pass
  If buy quantity but no get quantity
      If discount type = percent
        calculate value of the promotion for this item to compare later
      If discount type = dollar
        calculate value of the promotion for this item to compare later
      If discount type = price
        calculate value of the promotion for this item to compare later
      If discount amount = Free
        do nothing
        pass
  Else (assumes there is both buy and get)
    IF the quantity of the buy item in the cart is >= the buy_quantity (I think c.active_items is the items in the cart)
      If discount type = percent 
            calculate value of the promotion for this item to compare later
      If discount type = dollar
            calculate value of the promotion for this item to compare later
      If discount type = price    
            calculate value of the promotion for this item to compare later
      If discount amount = Free
        #Use a different var here like in select_cart_promotion - they will always get this promotion
        calculate the value of the promotion for these items
        do something here to ensure the get product is in the cart
  • 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-14T07:06:55+00:00Added an answer on May 14, 2026 at 7:06 am

    Take a look at cursors.

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

Sidebar

Related Questions

I'm trying to do something like this in postgres: UPDATE table1 SET (col1, col2)
Working on trying out the market licensing service, and I'm running into a few
Working with MySQL lately, from PHP, I am wondering about this: What is the
Working with Excel interop, I'm trying be very careful about not implicitly creating any
Working on an html5 app for a touchscreen windows xp computer that will be
Working with spring, below, the code of applicationContext-service.xml: <bean id=mediaObjectService class=path.MediaObjectServiceImpl> <property name=mediaObjectDao >
Working on a legacy ASP.NET application we've found that ASP.NET session gets used for
Working on site development using Drupal. Using View module also. I did defined severar
Working on Windows with VS2005 and struggling to understand the error messages I'm getting.
I've previously used sql-oracle just fine in Xemacs on XP and vista. However, now

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.