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]

 



I try with a CTE but cannot figure the syntax:


        WITH cte AS (
            SELECT uid 
            FROM words_social
            WHERE social = in_social
            AND sid = in_sid
            LIMIT 1
        )
        SELECT
                CASE WHEN c.uid = cte.uid THEN 1 ELSE 0 END,
                c.msg
        FROM    words_chat c 
        JOIN    words_games g USING (gid) 
        JOIN    words_users myself ON (myself.uid IN (g.player1, g.player2) AND myself.uid = cte.uid) 
        JOIN    words_users opponent ON (opponent.uid IN (g.player1, g.player2) AND myself.uid <> cte.uid) 
        JOIN    cte
        WHERE   c.gid    = in_gid
        AND     (c.uid = myself.uid OR NOT opponent.muted)
        ORDER BY c.CREATED ASC;

ERROR:  syntax error at or near "WHERE"
LINE 67:         WHERE   c.gid    = in_gid
                 ^

And if I remove the "JOIN cte" line, then the error is:

ERROR:  missing FROM-clause entry for table "cte"
LINE 64: ...elf.uid IN (g.player1, g.player2) AND myself.uid = cte.uid) 
                                                               ^

[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