저는 Postgres에서 일하고 있는데, 많은 행과 열이있는 전체 결과 집합을 저장 프로 시저 또는 함수로 보내야합니다. 이것이 가능한가? 그렇다면 구문에 대한 리소스는 어디서 볼 수 있습니까?전체 결과 집합을 SQL 함수로 보낼 수 있습니까?
OK 이것은 결과 집합을 보내지 않고 설정 한 방법입니다. 비교 논리를 깨고 두 개의 다른 지점에 넣으려고합니다.하지만 내 목표는 실제 프로모션을 찾는 것입니다. 한 곳에서의 논리, 내가 여기에서 한 것. 이것은 언젠가 바뀔지도 모릅니다. 비교 논리가 변하기 쉽지 않습니다. 그것은 꽤 표준입니다.
추진 품목 로직
저기가 될 트리거가 promo_objects, promo_buy_objects 및 promo_get_objects 테이블에 대한 INSERT에 설정합니다, 프로모션 테이블에 UPDATE 트리거가있을 것입니다. 외부 참조에 대한 년 - 트리거는 그 목적에 가장 적합한 홍보를 결정하는 저장 프로 시저라는 set_best_product_promos를 호출하고 그 다음에 새 테이블에 저장됩니다 :
promo_best_product_promos
PROMO_ID, OBJECT_ID, 만료
update_best_product_promos를 호출하고 PROMO_ID에서 활성 경우 보내드립니다 프로모션에 대한 -THE 트리거 = 사실은 그렇지가 프로모션
에 대한 모든 항목을 삭제하는 프로모션의 만료 날짜를 업데이트합니다새 테이블이 promo.sql 스크립트에 추가되었지만 함수가 작성 될 때까지 트리거 및 함수를 추가 할 수는 없습니다.
스크립트는 매일 밤 자정에 만료되어 만료 된 항목을 삭제합니다. 카트 코드 (응용 프로그램 코드)에 대한 PSEUDO 우리가 지금 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
편집 : 그래서 내가 같이이 카트 논리를 덤프 수도 있겠죠 스토어드 프로 시저뿐만 아니라 비교 로직을 위해 하나를 만들고 스토어드 프로 시저와 포터블 및 제네릭 모두에서 호황을 누릴 수 있습니까? set_best_product_promos에 대한
PSEUDO : get_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 :
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를 사용하려면 커서를 두 개 이상 호출해야하는 쿼리가 필요합니다. 이 문서의 다음 결과를 얻을 수 FETCH 말을, 그래서 당신은 커서 기능 루프 에서 선택 변수 끝 루프 에 커서를 가져올 것인가? – KacieHouser