사용자 메모 기록

:memo: 이 쿼리는 ‘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개의 좋아요