If I execute the following SQL
SELECT a.tran_date, a.tran_type, a.tran_number, a.amount_cust,
SUM(a.amount_cust) OVER (ORDER BY a.tran_date, a.tran_type, a.tran_row_id),
a.tran_row_id
FROM ar_trans a
I get this error -
ORDER BY list of RANGE window frame has total size of 8010 bytes. Largest size supported is 900 bytes.
The command looks innocuous, but in fact ar_trans is a VIEW. Here is the view definition -
CREATE VIEW ar_trans AS
SELECT 'ar_inv' AS tran_type, a.row_id AS tran_row_id, a.tran_number AS tran_number,
a.cust_row_id AS cust_row_id, a.tran_date AS tran_date, a.text AS text,
a.inv_net_cust + a.inv_tax_cust AS amount_cust, a.inv_net_local + a.inv_tax_local AS amount_local
FROM ar_tran_inv a WHERE a.posted = '1'
UNION ALL
SELECT 'ar_crn' AS tran_type, a.row_id AS tran_row_id, a.tran_number AS tran_number,
a.cust_row_id AS cust_row_id, a.tran_date AS tran_date, a.text AS text,
0 - (a.crn_net_cust + a.crn_tax_cust) AS amount_cust,
0 - (a.crn_net_local + a.crn_tax_local) AS amount_local
FROM ar_tran_crn a WHERE a.posted = '1'
UNION ALL
SELECT a.tran_type AS tran_type, a.row_id AS tran_row_id, a.tran_number AS tran_number,
a.cust_row_id AS cust_row_id,
CASE
WHEN a.tran_type = 'ar_rec' THEN y.tran_date
WHEN a.tran_type = 'cb_rec' THEN w.tran_date
END AS tran_date,
CASE
WHEN a.tran_type = 'ar_rec' THEN y.text
WHEN a.tran_type = 'cb_rec' THEN w.text
END AS text,
0 - (ROUND(a.arec_amount /
CASE
WHEN a.tran_type = 'ar_rec' THEN y.local_exch_rate
WHEN a.tran_type = 'cb_rec' THEN w.local_exch_rate
END
* a.cust_exch_rate, 2)) AS amount_cust,
0 - (ROUND(a.arec_amount /
CASE
WHEN a.tran_type = 'ar_rec' THEN y.local_exch_rate
WHEN a.tran_type = 'cb_rec' THEN w.local_exch_rate
END
, 2)) AS amount_local
FROM ar_rec_subtran a
LEFT JOIN ar_tran_rec_det z ON z.row_id = a.tran_det_row_id
LEFT JOIN ar_tran_rec y ON y.row_id = z.tran_row_id
LEFT JOIN cb_tran_rec_det x ON x.row_id = a.tran_det_row_id
LEFT JOIN cb_tran_rec w ON w.row_id = x.tran_row_id
WHERE
CASE
WHEN a.tran_type = 'ar_rec' THEN y.posted
WHEN a.tran_type = 'cb_rec' THEN w.posted
END = '1'
UNION ALL
SELECT 'ar_disc' AS tran_type, a.row_id AS tran_row_id, a.tran_number AS tran_number,
a.cust_row_id AS cust_row_id, a.tran_date AS tran_date, a.text AS text,
0 - (a.disc_net_cust + a.disc_tax_cust) AS amount_cust,
0 - (a.disc_net_local + a.disc_tax_local) AS amount_local
FROM ar_tran_disc a WHERE a.posted = '1'
If there is no other solution, I think I can eliminate the JOINs in the view definition by splitting the underlying table into two, but I would prefer to avoid that if possible.