我正在尝试按照这些instrunctions (No Value Returned)在PostgreSQL中编写一个过程,我的过程/函数是:
create or replace function flip_payment()
returns void as $$
begin
-- drop any previous working table
drop table if exists meta.fk_payment_copy;
-- insert the unique row into fk_payment_temp
SELECT distinct settlement_ref_no, order_type, fulfilment_type, seller_sku, wsn,
order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share
into fk_payment_copy
from fk_payment_temp;
-- empty the fk_payment_temp table
truncate table fk_payment_temp;
-- Insert the final filter data into fk_payment from copy table
INSERT INTO fk_payment(
settlement_ref_no, order_type, fulfilment_type, seller_sku, wsn,
order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share)
SELECT settlement_ref_no, order_type, fulfilment_type, seller_sku, wsn,
order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share
FROM fk_payment_copy;
-- delete copy table
drop table fk_payment_copy;
-- rechecking for duplication
SELECT min(id) as id, settlement_ref_no, order_type, fulfilment_type, seller_sku,
wsn, order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share
into fk_payment_copy
FROM fk_payment
group by settlement_ref_no, order_type, fulfilment_type, seller_sku,
wsn, order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share;
truncate table fk_payment;
--final data
INSERT INTO fk_payment(
id, settlement_ref_no, order_type, fulfilment_type, seller_sku,
wsn, order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share)
SELECT id, settlement_ref_no, order_type, fulfilment_type, seller_sku,
wsn, order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share
FROM fk_payment_copy;
drop table fk_payment_copy;
end;
$$ language plpgsql;
它给出了一个错误: 错误:“fk_payment_copy”不是已知变量
LINE 18: into fk_payment_copy
^
********** Error **********
ERROR: "fk_payment_copy" is not a known variable
SQL state: 42601
Character: 1010
此查询无需过程即可正常运行:
SELECT distinct settlement_ref_no, order_type, fulfilment_type, seller_sku, wsn,
order_id, order_item_id, order_date, dispatch_date, delivery_date,
cancellation_date, settlement_date, order_status, quantity, order_item_value,
sale_transaction_amount, discount_transaction_amount, refund,
protection_fund, total_marketplace_fee, service_tax, settlement_value,
commission_rate, commission, payment_rate, payment_fee, fee_discount,
cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee,
reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee,
storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount,
sub_category, total_offer_amount, my_offer_share, flipkart_offer_share
into fk_payment_copy
from fk_payment_temp;
此处fk_payment_copy
我已删除。
此查询是否返回了我必须声明的任何内容?