aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_save_rates_and_restrictions
Parameters
Name
Type
Mode
rate_data
jsonb
IN
currency
character varying
IN (DEFAULT NULL)
Definition
begin INSERT INTO rate_daily(rate_id, rate_date, currency_code, rate_amount, stop_sell, cta, ctd, min_stay, max_stay) with A as ( select * from jsonb_to_recordset(rate_data) as R(rate_id int, editable bool, rates jsonb) ) select A.rate_id, rec."date", $2, rec.amount, (restrictions->>'stop_sell')::bool as stop_sell, (restrictions->>'cta')::bool as cta, (restrictions->>'ctd')::bool as ctd, (restrictions->>'min_stay')::int as min_stay, (restrictions->>'max_stay')::int as max_stay from A, jsonb_to_recordset(A.rates) as rec("date" date, amount t_money, restrictions jsonb) WHERE NOT (rec.amount IS NULL AND restrictions->>'stop_sell' IS NULL AND restrictions->>'cta' IS NULL AND restrictions->>'ctd' IS NULL AND restrictions->>'min_stay' IS NULL AND restrictions->>'max_stay' IS NULL) on conflict(rate_id, rate_date, currency_code) do UPDATE SET rate_amount = excluded.rate_amount, stop_sell = excluded.stop_sell, cta = excluded.cta, ctd = excluded.ctd, min_stay = excluded.min_stay, max_stay = excluded.max_stay; return 0; end;