Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -258,16 +258,40 @@ norm AS (
|
||||
COALESCE(price, 0) AS price
|
||||
FROM input
|
||||
),
|
||||
dims_cache AS (
|
||||
-- Prefer PG's authoritative variant dimension table (mmitem_dim). Fall back to cache table if needed.
|
||||
dims_mmitem_dim AS (
|
||||
SELECT
|
||||
norm.product_code AS product_code,
|
||||
md.val1::bigint AS dim1,
|
||||
CASE
|
||||
WHEN md.val2 IS NULL OR md.val2 = 0 THEN NULL
|
||||
ELSE md.val2::bigint
|
||||
END AS dim3
|
||||
FROM norm
|
||||
JOIN mmitem mm
|
||||
ON mm.code = norm.product_code
|
||||
JOIN mmitem_dim md
|
||||
ON md.mmitem_id = mm.id
|
||||
AND COALESCE(md.is_active, TRUE) = TRUE
|
||||
WHERE md.val1 IS NOT NULL
|
||||
AND md.val1 > 0
|
||||
GROUP BY norm.product_code, md.val1, md.val2
|
||||
),
|
||||
dims_cache_table AS (
|
||||
SELECT
|
||||
NULLIF(BTRIM(c.product_code), '') AS product_code,
|
||||
c.dim1,
|
||||
c.dim3
|
||||
c.dim1::bigint AS dim1,
|
||||
c.dim3::bigint AS dim3
|
||||
FROM mk_mmitem_dim_combo c
|
||||
JOIN norm
|
||||
ON norm.product_code = c.product_code
|
||||
WHERE c.dim1 IS NOT NULL
|
||||
),
|
||||
dims_cache AS (
|
||||
SELECT product_code, dim1, dim3 FROM dims_mmitem_dim
|
||||
UNION
|
||||
SELECT product_code, dim1, dim3 FROM dims_cache_table
|
||||
),
|
||||
dims_sdprc AS (
|
||||
SELECT
|
||||
norm.product_code AS product_code,
|
||||
|
||||
Reference in New Issue
Block a user