Skip to content

Instantly share code, notes, and snippets.

@azass
Created June 23, 2025 22:22
Show Gist options
  • Save azass/7dc6fa309633edb9e0e85ec10f51e292 to your computer and use it in GitHub Desktop.
Save azass/7dc6fa309633edb9e0e85ec10f51e292 to your computer and use it in GitHub Desktop.
ハッシュ化
-- 事前に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