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

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Displaying chat by punished users only to themselves (db fiddle attached)
Date: 2022-05-04 15:40:35
Message-ID: CAKFQuwaoJ4rKbWX+f20tF3+UeeGpr=P+RBCY1HxELpMoJ77XRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, May 4, 2022 at 8:36 AM Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
wrote:

> David, I try then the following -
>
> On Wed, May 4, 2022 at 5:28 PM David G. Johnston <
> david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
>> You missed quoting the part where I describe the on clauses you need to
>> distinguish between "them" and "me"
>>
>> Me: u.uid in (player...) and (s.uid = u.uid)
>> Them: u.uid in (player...) and (s.uid <> u.uid)
>>
>>
>
> https://dbfiddle.uk/?rdbms=postgres_14&fiddle=048b9b9c7c55256c1a478d7c90cd2667
>
> SELECT
> CASE WHEN c.uid = s.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 = s.uid)
> JOIN words_users opponent ON (opponent.uid IN (g.player1,
> g.player2) AND myself.uid <> s.uid)
> JOIN words_social s ON (s.uid = myself.uid)
> WHERE c.gid = in_gid
> AND s.social = in_social
> AND s.sid = in_sid
> AND (c.uid = myself.uid OR NOT opponent.muted)
>
> ORDER BY c.CREATED ASC;
>
> And get the syntax error which don't quite understand:
>
> ERROR: missing FROM-clause entry for table "s"
> LINE 57: ...yself.uid IN (g.player1, g.player2) AND myself.uid = s.uid)
> ^
>
> Probably because "myself" needs "s" and vice versa?
>
>
Well, that is basically why I was going on about the oddity of having
social be a part of the main query. Personally I would write it as
"myself.uid = in_uid", but you don't have an in_uid to reference. Decide
how you want to do something equivalent.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2022-05-04 15:53:21 Re: Displaying chat by punished users only to themselves (db fiddle attached)
Previous Message Alexander Farber 2022-05-04 15:39:58 Re: Displaying chat by punished users only to themselves (db fiddle attached)