python - Nesting Case Statements in postgresql -


I have this python function which I am trying to convert to SQL in PostGrSCL 9.2.

  Def calc_open_order (xOrder): temp_row = xOrder.so_reportL [0] open_closed_status = 'OPEN' order_status = temp_row [3] If order_status == 'FAILED': open_closed_status = 'off' Elif Order_status == deleted '': open_closed_status = 'off' Elif order_status == 'NO_PENDING_ACTION': open_closed_status = 'off' Elif Order_status == 'PENDING_REMOVED': Open_closed_status = 'off' and # shipping group status any_open_sg = xOrder.so_reportL wrong sd_row: If sd_row [45] == 'PENDING_SHIPMENT': any_open_sg = true elif sd_row [45] == 'processing': any_open_sg = true elif sd_row [45] == 'early': any_open_sg = true Elif Sd_row [ 45] == 'PENDING_MERCHANT_ Action': any_open_sg = true if any_open_sg == incorrect: open_closed_status = 'off' # if open_closed_status == 'shutdown': ord_ Open_ind = 'false' balance: ord_open_ind = 'true' return ord_open_ind,  

I have changed this argument in SQL using a case statement:

 < select the code> in the case when (the case when the case is when (in ord_status failed ',' deleted ',' NO_PENDING_ACTION 'NO_PEDNING_ACTION' PENDING_REMOVED ') when (' PENDING_SHIPMENT in SHIPPING_STATUS, 'processing' Then 'right' or 'wrong' end = 'when' id 'is not closed (' failed ',' deleted ',' NO_PENDING_ACTION ',' NO_PEDNING_ACTION ',' PENDING_REMOVED 'then' open ',' initial ',' PENDING_MERCHANT_ACTION ') OPEN_ORD as incorrect 'then' off ' ER_IND  

Please note that sd_row [45] is the same shipping_status field is my case statement correct?

may be (untested):

 select  when ord_status IN ( 'failed', 'deleted', 'NO_PENDING_ACTION', 'PENDING_REMOVED') or shipping_status not ( 'PENDING_SHIPMENT', 'processing', 'preliminary', 'PENDING_MERCHANT_ACTION') and 'false' :: text to all other 'it True 'end_open_ind as the end'  

The return type should probably be better, but that is not in your question.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -