Last active
April 26, 2022 19:32
-
-
Save vvgsrk/de682ce8c686b3b1a0d18d19e178eeed to your computer and use it in GitHub Desktop.
Incremental table query on snowflake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace transient table dev_edw_dbt_incremental_model_test.dbt_src_product_management.src_product_management_product_latest_incremental as | |
( | |
WITH ranked_data AS ( | |
SELECT | |
ROW_NUMBER() over ( | |
PARTITION BY product_id | |
ORDER BY | |
__event_ts DESC | |
) AS row_rank, | |
* | |
FROM dev_edw_dbt_incremental_model_test.dbt_src_product_management.src_product_management_product_history | |
) | |
SELECT | |
"PRODUCT_ID", | |
"PRODUCT_NAME", | |
"PRICE_PER_UNIT", | |
"BASIC_UNIT", | |
"IS_STOCK_LIMITED", | |
"IS_ACTIVE_FOR_SALE", | |
"__EVENT_TS", | |
"__LOAD_TS", | |
HASH( | |
product_id | |
) AS __uuid | |
FROM | |
ranked_data | |
WHERE | |
row_rank = 1 | |
ORDER BY __load_ts desc | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment