Search Postgresql Archives

Re: Displaying chat by punished users only to themselves (db fiddle attached)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Is that the right way to do it?

https://dbfiddle.uk/?rdbms=postgres_14&fiddle=7bd74243397da61ddc4c216ad919c7cc

        WITH myself AS (
            SELECT uid
            FROM words_social
            WHERE social = in_social
            AND sid = in_sid
            LIMIT 1
        )
        SELECT
                CASE WHEN c.uid = myself.uid THEN 1 ELSE 0 END,
                c.msg
        FROM    myself
        JOIN    words_chat c ON TRUE
        JOIN    words_games g USING (gid)
        JOIN    words_users opponent ON (opponent.uid IN (g.player1, g.player2) AND opponent.uid <> myself.uid)
        WHERE   c.gid = in_gid
        -- always show myself my own chat messages
        AND     c.uid = myself.uid
        -- otherwise only show messages by not muted opponents
        OR      NOT opponent.muted
        ORDER BY c.created ASC;

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux