我正在使用此代码:
def saveUploadedInventory(self, inventory_file,user_id):
print "Inventory File"
with open('uploaded_inventory_sheet.csv','wb+') as destination:
for chunk in inventory_file.chunks():
destination.write(chunk)
print "Inventory Saved."
f = open('uploaded_inventory_sheet.csv','rb')
with open('uploaded_inventory_sheet.csv') as f:
next(f)
content = StringIO('\n'.join(line for line in f))
self.cur.copy_from(content,'fk_payment_temp', sep=',', null='null', columns=('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', 'swach_bharat_cess',
'settlement_value', 'commission_rate', 'commission', 'payment_rate',
'payment_fee', 'fee_discount', 'cancellation_fee', 'fixed_fee', 'emi_fee',
'total_weight', 'weight_type', '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'))
f.close()
这是错误的:
DataError at /upload/ invalid input syntax for type date: "" CONTEXT: COPY fk_payment_temp, line 1, column cancellation_date: ""
有很多日期列没有任何价值。
我的表结构是:
CREATE TABLE fk_payment_temp
(
id serial NOT NULL,
settlement_ref_no character varying,
order_type character varying,
fulfilment_type character varying,
seller_sku character varying,
wsn character varying,
order_id character varying,
order_item_id character varying,
order_date timestamp without time zone,
dispatch_date date default null,
delivery_date date default null,
cancellation_date date default null,
settlement_date date,
order_status character varying,
.....
任何机构都可以帮助我解决这个问题。
更改python代码还是更改postgresql结构?
将日期转换为 varchar 是最不重要的选择。