Re: Forward declaration of table

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Forward declaration of table
Date: 2016-08-24 23:31:20
Message-ID: fd937f00-53b7-f9e0-91ba-97000d0cc2a0@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/24/2016 01:27 PM, Alexander Farber wrote:
> Hello again,
>
> I have went the ALTER TABLE route to add my 2 "cyclic" FKs:
>
> https://gist.github.com/afarber/c40b9fc5447335db7d24
>
> And now I have these 2 tables in my 9.5.3 database:

>
> Why aren't m.tiles and m.score returned please?

Reformatted your LEFT JOIN query(courtesy of http://sqlformat.darold.net/) :

SELECT
m.tiles,
m.score,
g.gid,
extract (
EPOCH
FROM
g.created ) ::INT AS created,
g.player1,
COALESCE (
g.player2,
0 ) AS player2,
COALESCE (
extract (
EPOCH
FROM
g.played1 ) ::INT,
0 ) AS played1,
COALESCE (
extract (
EPOCH
FROM
g.played2 ) ::INT,
0 ) AS played2,
array_to_string (
g.hand1,
'' ) AS hand1,
array_to_string (
g.hand2,
'' ) AS hand2,
g.bid
FROM
words_games g
LEFT JOIN words_moves m ON (
g.mid1 = m.mid
OR g.mid2 = m.mid )
WHERE
g.player1 = 1
OR g.player2 = 1;

Looking at your tables I would start with something like:

SELECT
wm.tiles, wm.score
FROM
word_games AS wg
JOIN
word_moves AS wm
ON
wg.gid = wm.gid
WHERE
(wg.player1 = 1
OR
wg.player2 = 1)

>
> Regards
> Alex

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Rogers 2016-08-25 00:27:46 Re: Determining table change in an event trigger
Previous Message Theron Luhn 2016-08-24 22:47:16 Understanding Postgres Memory Usage