Created
June 23, 2025 22:22
-
-
Save azass/7dc6fa309633edb9e0e85ec10f51e292 to your computer and use it in GitHub Desktop.
ハッシュ化
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
-- 事前にpgcrypto拡張を有効化 (初回のみ) | |
-- CREATE EXTENSION IF NOT EXISTS pgcrypto; | |
SELECT | |
product_code, | |
encode(digest( -- digestでハッシュを計算し、encodeで16進数文字列に | |
CONCAT_WS( | |
'|', | |
product_name, | |
COALESCE(price::text, ''), -- 数値型をtextに変換し、NULLは空文字に | |
COALESCE(TO_CHAR(launch_date, 'YYYY-MM-DD'), '') -- 日付をフォーマットし、NULLは空文字に | |
), 'sha256'), 'hex') AS row_hash | |
FROM | |
M_PRODUCTS | |
ORDER BY | |
product_code; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment