我在Postgres工作,我需要发送一个完整的结果集与许多行和列到存储过程或函数。这可能吗?如果是这样,我在哪里可以看到语法资源?您可以将完整的结果集发送到SQL函数吗?
好的,这是我无法发送结果集而设置的,它迫使我打破比较逻辑并将其放在两个不同的位置,但我的目标是保持实际发现的促进我在这里完成了一个地方的逻辑。这可能会改变一天,比较逻辑不太可能改变,这是相当标准的。
促进行项目逻辑
-there将在INSERT为promo_objects,promo_buy_objects和promo_get_objects表设置为触发器,将有对电视节目预告表中的UPDATE触发器。 的外部参照-The触发器将调用存储过程调用set_best_product_promos将决定哪些促销是最好的那个对象,然后将它保存到一个新表:
promo_best_product_promos
PROMO_ID, OBJECT_ID, 到期日期
-The触发宣传片将调用update_best_product_promos,将在PROMO_ID如果主动发送=真会更新该促销的截止日期否则将删除所有条目为促销
新表已添加到promo.sql脚本中,但只有在写入函数后才能添加触发器和函数。
脚本将在每天午夜运行以删除已过期的条目。 伪推车代码(应用程序代码) 运行联合查询,就像我们现在shown_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
编辑:所以我想我可以放弃这个车逻辑一个存储过程,然后为比较逻辑做一个,并在存储过程和便携式和泛型中繁荣它的一切?
拟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
拟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
所以我必须使用FETCH,因为我正在做的查询w /游标需要从多个地方调用。它说FETCH将获得文档中的下一个结果,所以你会 从光标功能 环 选择取光标移到变量 结束循环 ? – KacieHouser 2010-04-22 18:54:25