Changes between Version 1 and Version 2 of Views


Ignore:
Timestamp:
09/26/25 12:44:56 (3 weeks ago)
Author:
226026
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Views

    v1 v2  
    5454GROUP BY c.project_resource_id, c.name,pr.id
    5555}}}
     56
     57== Поглед за групирање на топици и проекти за прикажување на почетната страница
     58
     59{{{
     60create or replace view v_named_threads as
     61WITH topics_projects AS (SELECT pr.id,
     62                                pr.title,
     63                                'projects'::text AS "type"
     64                         FROM project_thread pr
     65                         UNION
     66                         SELECT topic_thread.id,
     67                                topic_thread.title,
     68                                'topics'::text AS "type"
     69                         FROM topic_thread),
     70     topics_projects_threads AS (SELECT t.id,
     71                                        t.content,
     72                                        tp.type,
     73                                        tp.title,
     74                                        u.username,
     75                                        u.id        AS user_id,
     76                                        t.created_at
     77                                 FROM thread t
     78                                          JOIN users u ON u.id = t.is_created_by
     79                                          JOIN topics_projects tp ON tp.id = t.id)
     80        ,
     81     named_threads_tags as (select tt.thread_id           as "id",
     82                                   array_agg(tt.tag_name) as "tags"
     83                            from tag_assigned_to_thread tt
     84                            where tt.thread_id in (select id from topics_projects_threads)
     85                            group by tt.thread_id)
     86SELECT tpt.id,
     87       tpt.content,
     88       tpt.title,
     89       tpt.type,
     90       tpt.username,
     91       tpt.user_id,
     92       tpt.created_at,
     93       coalesce((select ntt.tags as "tags"
     94                 from named_threads_tags ntt
     95                 where ntt.id = tpt.id),'{}') as "tags"
     96FROM topics_projects_threads tpt;
     97}}}