postgresql - perform true on joined tables -
in postgresql 8.4.13 have 2 tables representing card games (each 3 players) , score results of games. players identified id
column , games gid
:
# \d pref_games table "public.pref_games" column | type | modifiers --------+-----------------------------+---------------------------------------------------------- gid | integer | not null default nextval('pref_games_gid_seq'::regclass) rounds | integer | not null stamp | timestamp without time zone | default now() indexes: "pref_games_pkey" primary key, btree (gid) referenced by: table "pref_scores" constraint "pref_scores_gid_fkey" foreign key (gid) references pref_games(gid) on delete cascade # \d pref_scores table "public.pref_scores" column | type | modifiers ---------+-----------------------+----------- id | character varying(32) | not null gid | integer | not null money | integer | not null last_ip | inet | quit | boolean | indexes: "pref_scores_pkey" primary key, btree (id, gid) "pref_scores_gid_index" btree (gid) foreign-key constraints: "pref_scores_gid_fkey" foreign key (gid) references pref_games(gid) on delete cascade "pref_scores_id_fkey" foreign key (id) references pref_users(id) on delete cascade
i'm trying find out if player id='ok261593357402'
has ever played player id='mr3689735717800138910'
- can allow them grade each other @ web site.
i think need call perform true
on inner join
- correct please?
so i'm trying:
# select * pref_games g inner join pref_scores s on (s.gid=g.gid) s.id='ok261593357402'; gid | rounds | stamp | id | gid | money | last_ip | quit ---------+--------+----------------------------+----------------+---------+-------+----------------+------ 2124241 | 20 | 2013-05-01 12:26:54.052086 | ok261593357402 | 2124241 | 28 | 93.232.91.105 | f 2125575 | 17 | 2013-05-01 16:53:21.090822 | ok261593357402 | 2125575 | 32 | 93.232.91.105 | f 2125881 | 20 | 2013-05-01 17:47:26.15633 | ok261593357402 | 2125881 | -31 | 93.232.91.105 | f 2126242 | 0 | 2013-05-01 18:41:06.769132 | ok261593357402 | 2126242 | 0 | 93.232.91.105 | f 2126244 | 0 | 2013-05-01 18:41:12.495192 | ok261593357402 | 2126244 | 0 | 93.232.91.105 | t 2126259 | 0 | 2013-05-01 18:42:39.974518 | ok261593357402 | 2126259 | 0 | 93.232.91.105 | t 2126613 | 33 | 2013-05-01 19:27:11.88462 | ok261593357402 | 2126613 | -132 | 93.232.91.105 | f 2126813 | 0 | 2013-05-01 19:57:05.23061 | ok261593357402 | 2126813 | 0 | 93.232.91.105 | t 2127299 | 20 | 2013-05-01 20:36:42.021133 | ok261593357402 | 2127299 | 136 | 93.232.91.105 | f 2127821 | 0 | 2013-05-01 21:33:32.168757 | ok261593357402 | 2127821 | 0 | 93.232.91.105 | f 2127830 | 0 | 2013-05-01 21:34:47.694645 | ok261593357402 | 2127830 | 0 | 93.232.91.105 | t 2128012 | 21 | 2013-05-01 22:04:03.850061 | ok261593357402 | 2128012 | 55 | 93.232.91.105 | f 2129551 | 13 | 2013-05-02 10:08:37.348426 | ok261593357402 | 2129551 | -32 | 79.250.39.175 | f 2129818 | 13 | 2013-05-02 11:21:50.998484 | ok261593357402 | 2129818 | 71 | 79.250.39.175 | f 2130467 | 11 | 2013-05-02 13:55:00.034698 | ok261593357402 | 2130467 | -79 | 79.250.39.175 | f 2130470 | 0 | 2013-05-02 13:55:41.298932 | ok261593357402 | 2130470 | 0 | 79.250.39.175 | f 2130476 | 0 | 2013-05-02 13:56:22.359713 | ok261593357402 | 2130476 | 0 | 79.250.39.175 | f .....
but see id='ok261593357402'
above, i.e. expecting see game partners too, not delivered.
i've tried:
# select * pref_games g left outer join pref_scores s on (s.gid=g.gid) s.id='ok261593357402'; gid | rounds | stamp | id | gid | money | last_ip | quit ---------+--------+----------------------------+----------------+---------+-------+----------------+------ 2124241 | 20 | 2013-05-01 12:26:54.052086 | ok261593357402 | 2124241 | 28 | 93.232.91.105 | f 2125575 | 17 | 2013-05-01 16:53:21.090822 | ok261593357402 | 2125575 | 32 | 93.232.91.105 | f 2125881 | 20 | 2013-05-01 17:47:26.15633 | ok261593357402 | 2125881 | -31 | 93.232.91.105 | f 2126242 | 0 | 2013-05-01 18:41:06.769132 | ok261593357402 | 2126242 | 0 | 93.232.91.105 | f 2126244 | 0 | 2013-05-01 18:41:12.495192 | ok261593357402 | 2126244 | 0 | 93.232.91.105 | t 2126259 | 0 | 2013-05-01 18:42:39.974518 | ok261593357402 | 2126259 | 0 | 93.232.91.105 | t 2126613 | 33 | 2013-05-01 19:27:11.88462 | ok261593357402 | 2126613 | -132 | 93.232.91.105 | f 2126813 | 0 | 2013-05-01 19:57:05.23061 | ok261593357402 | 2126813 | 0 | 93.232.91.105 | t ...
unfortunately same result...
should maybe make series of select
s combined exists in
instead?
i'm trying find out if player
id='ok261593357402'
has ever played playerid='mr3689735717800138910'
it's shorter / faster / simpler / more elegant use if exists ...
in plpgsql perform
trailing if found ...
:
if exists ( select 1 pref_scores p1 join pref_scores p2 using (gid) p1.id = 'ok261593357402' , p2.id = 'mr3689735717800138910' ) -- stuff end if;
you don't need table pref_games
@ answer question.
Comments
Post a Comment