このクエリは、「plugin_store_rows」テーブルからユーザーノートを取得・フォーマットし、各ノートを対応するユーザーID、作成日、内容、作成者のIDと関連付けます。結果として、関連する詳細情報を含むユーザーノートの包括的なリストが得られます。
WITH user_notes AS (
SELECT
REPLACE(key, 'notes:', '')::int AS user_id,
notes.value->>'created_at' AS created_at,
notes.value->>'raw' AS user_note,
notes.value->>'created_by' AS created_by
FROM plugin_store_rows,
LATERAL json_array_elements(value::json) notes
WHERE plugin_name = 'user_notes'
ORDER BY 2 DESC
)
SELECT
un.user_id,
un.created_at::date,
un.user_note,
un.created_by AS created_by_user_id
FROM user_notes un
JOIN users u ON u.id = un.user_id
「いいね!」 7