[supabase] structure of query does not match function result type

김동욱·2024년 2월 28일

structure of query does not match function result type 이슈

해당 이슈는 조회된 컬럼의 타입과 결과 컬럼에 지정된 타입이 다르면 생기는 이슈

기존에 테이블 tb_user_comment의 comment_created_at 컬럼이 timestamptz 으로 지정되어있었음

timestamptz는 타임존을 포함한 일시를 표현하는 타입임
타입을 timestamp 로 수정 후 실행시 정상 작동

CREATE OR REPLACE FUNCTION get_image_comments(image_id_param int) 
RETURNS TABLE (
  comment_id bigint,
  user_id bigint,
  user_name text,
  comment_image_id bigint,
  comment_content text,
  comment_created_at timestamp,
  comment_is_deleted bool
) AS $$
BEGIN
  RETURN QUERY
    SELECT
      tuc.comment_id,
      tup.user_id,
      tup.user_name,
      tuc.comment_image_id,
      tuc.comment_content,
      tuc.comment_created_at,
      tuc.comment_is_deleted
    FROM
      tb_user_comment tuc
    INNER JOIN tb_user_profile tup ON tuc.comment_user_id = tup.user_id
    WHERE
      tuc.comment_image_id = image_id_param
    AND tuc.comment_is_deleted = false
    ORDER BY
      tuc.comment_created_at DESC;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM get_image_comments(5535486);
profile
백엔드 개발자

0개의 댓글