SQL : CREATE OR REPLACE PROCEDURE insert_display_order_part1(
in_gondola_layout_version TEXT,
in_system_date DATE,
in_task_id TEXT,
in_store_version TEXT
)
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO w_display_order_send(
store_code, item_code, gondola_furniture_type,
display_gondola, display_shelf, display_row,
display_face, display_order_input_datetime,
extraction_date, update_datetime,
update_function_id, update_person_id, update_count
)
SELECT
tmp.store_code,
tmp.item_code,
CASE
WHEN tmp.gondola_furniture_type IS NULL THEN NULL
ELSE LPAD(TRIM(tmp.gondola_furniture_type), 3, '0')
END,
tmp.display_gondola,
tmp.display_shelf,
tmp.display_row,
tmp.display_face,
tmp.display_order_input_datetime,
in_system_date,
CURRENT_TIMESTAMP,
in_task_id,
in_task_id,
0
FROM (
SELECT
te1.store_code,
tn.item_code,
gl1.gondola_furniture_type,
tn.display_gondola,
tn.display_shelf,
tn.display_row,
tn.display_face,
tn.display_order_input_datetime,
ROW_NUMBER() OVER (
PARTITION BY te1.store_code, tn.item_code, tn.label_code
ORDER BY tn.display_order_input_datetime DESC
) AS registrationOrder
FROM m_store_number te1
INNER JOIN m_display tn
ON te1.original_store_code = tn.original_store_code
LEFT JOIN m_gondola_layout gl1
ON gl1.version = in_gondola_layout_version
AND tn.original_store_code = gl1.original_store_code
AND tn.display_gondola = gl1.gondola_number
WHERE
te1.version = in_store_version
AND in_system_date BETWEEN te1.apply_start_date AND te1.apply_end_date
) AS tmp
WHERE tmp.registrationOrder <= 2
SQL : unterminated dollar-quoted string at or near "$$
BEGIN
INSERT INTO w_display_order_send(
store_code, item_code, gondola_furniture_type,
display_gondola, display_shelf, display_row,
display_face, display_order_input_datetime,
extraction_date, update_datetime,
update_function_id, update_person_id, update_count
)
SELECT
tmp.store_code,
tmp.item_code,
CASE
WHEN tmp.gondola_furniture_type IS NULL THEN NULL
ELSE LPAD(TRIM(tmp.gondola_furniture_type), 3, '0')
END,
tmp.display_gondola,
tmp.display_shelf,
tmp.display_row,
tmp.display_face,
tmp.display_order_input_datetime,
in_system_date,
CURRENT_TIMESTAMP,
in_task_id,
in_task_id,
0
FROM (
SELECT
te1.store_code,
tn.item_code,
gl1.gondola_furniture_type,
tn.display_gondola,
tn.display_shelf,
tn.display_row,
tn.display_face,
tn.display_order_input_datetime,
ROW_NUMBER() OVER (
PARTITION BY te1.store_code, tn.item_code, tn.label_code
ORDER BY tn.display_order_input_datetime DESC
) AS registrationOrder
FROM m_store_number te1
INNER JOIN m_display tn
ON te1.original_store_code = tn.original_store_code
LEFT JOIN m_gondola_layout gl1
ON gl1.version = in_gondola_layout_version
AND tn.original_store_code = gl1.original_store_code
AND tn.display_gondola = gl1.gondola_number
WHERE
te1.version = in_store_version
AND in_system_date BETWEEN te1.apply_start_date AND te1.apply_end_date
) AS tmp
WHERE tmp.registrationOrder <= 2"