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

Поиск
Список
Период
Сортировка
От Alexander Farber
Тема Re: Displaying chat by punished users only to themselves (db fiddle attached)
Дата
Msg-id CAADeyWgZ1QXEZvBHhKEeJ60zMPGj3_gP+6qQ=4eNC=pAe7-=zA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Displaying chat by punished users only to themselves (db fiddle attached)  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
David, thanks but what do you mean by the last comment -

On Wed, May 4, 2022 at 7:44 PM David G. Johnston <david.g.johnston@gmail.com> wrote:
Using (SELECT uid FROM myself) provides the same result without the from/join reference; the usage in the case and the where clause could be rewritten to use opponent.uid so myself.uid only appears once.


I have applied your first 2 comments in


        WITH myself AS (
            SELECT uid 
            FROM words_social
            WHERE social = in_social
            AND sid = in_sid
        )
        SELECT
                CASE WHEN c.uid = myself.uid THEN 1 ELSE 0 END,
                c.msg
        FROM    words_chat c
        JOIN    myself 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;

but where to put the (SELECT uid FROM myself), I do not understand?

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Displaying chat by punished users only to themselves (db fiddle attached)
Следующее
От: JORGE MALDONADO
Дата:
Сообщение: WIN1252 vs UTF8 database encoding