gpt4 book ai didi

postgresql - 您可以将完整的结果集发送到 SQL 函数吗?

转载 作者:行者123 更新时间:2023-11-29 13:07:31 25 4
gpt4 key购买 nike

我在 Postgres 中工作,我需要将包含许多行和列的完整结果集发送到存储过程或函数中。这可能吗?如果是这样,我在哪里可以看到语法资源?

好的,这就是我在无法发送结果集的情况下设置它的方式,它迫使我打破比较逻辑并将其放在两个不同的位置,但是我的目标是保持实际查找促销逻辑在一个地方,我已经在这里完成了。这可能有一天会改变,比较逻辑不太可能改变,这是非常标准的。

促销行项目逻辑

-将为 promo_objects、promo_buy_objects 和 promo_get_objects 表在 INSERT 上设置触发器,在促销表上将有一个 UPDATE 触发器。-外部参照的触发器将调用一个名为 set_best_product_promos 的存储过程,该过程将决定哪个促销最适合该对象,然后将其保存到一个新表中:

promo_best_product_promos

促销代码,object_id,过期日期

- 促销触发器将调用 update_best_product_promos 并将发送 promo_id,如果 active = true 它将更新该促销的到期日期,否则它将删除该促销的所有条目

新表已添加到 promo.sql 脚本中,但是在编写函数之前无法添加触发器和函数。

脚本将在每晚午夜运行以删除已过期的条目。PSEUDO FOR 购物车代码(应用程序代码)像我们现在显示的那样运行联合查询_object_promotions(这会获取该商品的所有可用促销)

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

编辑:所以我想我也可以将这个购物车逻辑转储为一个存储过程,然后为比较逻辑创建一个,然后将其全部存储在存储过程中,并且可移植和通用?

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

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

最佳答案

看看cursors .

关于postgresql - 您可以将完整的结果集发送到 SQL 函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2685120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com