DROP VIEW "public"."tbe_documents_view";--> statement-breakpoint CREATE VIEW "public"."tbe_documents_view" AS (select dr.id as "document_review_id", COALESCE(dr.tbe_session_id, vd.tbe_session_id) as "tbe_session_id", CASE WHEN dr.id IS NOT NULL THEN dr.document_source WHEN vd.id IS NOT NULL THEN 'vendor' ELSE NULL END as "document_source", COALESCE(dr.buyer_attachment_id, vd.id) as "document_id", COALESCE(dr.document_type, vd.document_type) as "document_type", COALESCE(dr.document_name, vd.original_file_name) as "document_name", COALESCE(ba_rev.original_file_name, vd.original_file_name) as "original_file_name", COALESCE(ba_rev.file_path, vd.file_path) as "file_path", COALESCE(ba_rev.file_size, vd.file_size) as "file_size", COALESCE(ba_rev.file_type, vd.file_type) as "file_type", COALESCE(dr.review_status, vd.review_status, '미검토') as "review_status", dr.technical_compliance as "technical_compliance", dr.quality_acceptable as "quality_acceptable", COALESCE(dr.requires_revision, false) as "requires_revision", COALESCE(dr.has_pdftron_comments, false) as "has_pdftron_comments", dr.pdftron_document_id as "pdftron_document_id", COALESCE(dr.pdftron_annotation_count, 0) as "pdftron_annotation_count", COALESCE(dr.reviewed_by, vd.reviewed_by) as "reviewed_by", COALESCE(dr.reviewed_at, vd.reviewed_at) as "reviewed_at", COALESCE(dr.review_comments, vd.review_comments) as "review_comments", vd.submitted_by as "submitted_by", vd.submitted_at as "submitted_at", COALESCE(dr.created_at, vd.submitted_at) as "created_at", COALESCE(dr.updated_at, vd.submitted_at) as "updated_at" from ( SELECT * FROM rfq_last_tbe_document_reviews ) dr FULL OUTER JOIN ( SELECT * FROM rfq_last_tbe_vendor_documents ) vd ON false left join "rfq_last_attachments" "ba" on dr.buyer_attachment_id = "ba"."id" left join "rfq_last_attachment_revisions" "ba_rev" on dr.buyer_attachment_revision_id = "ba_rev"."id");