Skip to main content
Commonmark migration
Source Link

##Stored functions

Stored functions

##Calculations

Calculations

##Spread it out

Spread it out

###Explicit create table in insert statement

Explicit create table in insert statement

##Stored functions

##Calculations

##Spread it out

###Explicit create table in insert statement

Stored functions

Calculations

Spread it out

Explicit create table in insert statement

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I have put together a while back a stored functionstored function used to insert data into multiple tables in one transaction. Perhaps it will inspire you to write something with that kind of logic, as a model.

I have put together a while back a stored function used to insert data into multiple tables in one transaction. Perhaps it will inspire you to write something with that kind of logic, as a model.

I have put together a while back a stored function used to insert data into multiple tables in one transaction. Perhaps it will inspire you to write something with that kind of logic, as a model.

added 7 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155

This one comes up constantly in your insert query:

("Selected_Period".da_spread_diff*-1)

Put that one in a variable too... (sorry, data type is unclear, use whatever is appropriate)

period_da_spread_diff INTEGER := SELECT (da_spread_diff*-1) FROM public.darts_calculated_partitioned;

That immensely simplifies your code:

   period_da_spread_diff AS "LMP DA A-B Spread", 
   AVG(period_da_spread_diff) as "LMP DA A-B Spread PL", 
     0.50 AS "Submitted Bid",
    CASE WHEN period_da_spread_diff <=0.50 THEN TRUE ELSE FALSE END AS "Filled",
    CASE WHEN period_da_spread_diff <=0.50 THEN 1 ELSE 0 END AS "Filled %",
    CASE WHEN period_da_spread_diff <=0.50 THEN period_da_spread_diff END AS "Price Filled At",


This one comes up constantly in your insert query:

("Selected_Period".da_spread_diff*-1)

Put that one in a variable too... (sorry, data type is unclear, use whatever is appropriate)

period_da_spread_diff INTEGER := SELECT (da_spread_diff*-1) FROM public.darts_calculated_partitioned;

That immensely simplifies your code:

   period_da_spread_diff AS "LMP DA A-B Spread", 
   AVG(period_da_spread_diff) as "LMP DA A-B Spread PL", 
     0.50 AS "Submitted Bid",
    CASE WHEN period_da_spread_diff <=0.50 THEN TRUE ELSE FALSE END AS "Filled",
    CASE WHEN period_da_spread_diff <=0.50 THEN 1 ELSE 0 END AS "Filled %",
    CASE WHEN period_da_spread_diff <=0.50 THEN period_da_spread_diff END AS "Price Filled At",

added 7 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155
Loading
Added more information
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155
Loading
deleted 8 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155
Loading
added 47 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155
Loading
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155
Loading