-- View: public.latest_document_versions

-- DROP VIEW public.latest_document_versions;

CREATE OR REPLACE VIEW public.latest_document_versions
 AS
 SELECT dv.doc_id,
    dv.content,
    dv.version_number,
    dv.updated_at
   FROM document_versions dv
     JOIN ( SELECT document_versions.doc_id,
            max(document_versions.version_number) AS max_version
           FROM document_versions
          GROUP BY document_versions.doc_id) latest ON dv.doc_id = latest.doc_id AND dv.version_number = latest.max_version;

ALTER TABLE public.latest_document_versions
    OWNER TO dbuser01;

