pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: subselect prob in view
Date: Mon, 21 Jun 2004 11:10:39 +0100
Message-ID: <200406211110.39940.gary.stainburn@ringways.co.uk> (raw)

Hi folks,

I've got the view:

create view nrequest_details as
  select r.r_id, r_registration, r.r_chassis, r.r_vehicle, 
r.r_fuel,r.r_pack_mats,
         r.r_delivery, r_delivery::date-now()::date as r_remaining, 
         r.r_created, r.r_completed,
         d.d_des, de.de_des,
         u.u_id, u.u_userid, u.u_username, u.u_salesman, u.u_target,
         t.t_id, t.t_des,
         s.s_id, s.s_des,
         c.c_id, c.c_des
     from requests r, users u, request_types t, 
          request_states s, dealerships d, departments de, customers c
     where r_d_id = d.d_id and
           r_s_id = s.s_id and
           r_c_id = c.c_id and
           r_t_id = t.t_id and
           r_d_id = d.d_id and
           r_de_id = de.de_id and
           r_u_id = u.u_id;

to which I want to add a count (2 eventually), so that it becomes:

create view nrequest_details as
  select r.r_id, r_registration, r.r_chassis, r.r_vehicle, 
r.r_fuel,r.r_pack_mats,
         r.r_delivery, r_delivery::date-now()::date as r_remaining, 
         r.r_created, r.r_completed,
         d.d_des, de.de_des,
         u.u_id, u.u_userid, u.u_username, u.u_salesman, u.u_target,
         t.t_id, t.t_des,
         s.s_id, s.s_des,
         c.c_id, c.c_des,
         co.count as comments
--       cor.count as comments_unseen
     from requests r, users u, request_types t, 
          request_states s, dealerships d, departments de, customers c
          left outer join (select co_r_id, count(co_r_id) from comments group 
by co_r_id) co on
            co.co_r_id = r.r_id
--        left outer join (select co_r_id, count(co_r_id) from comments where 
cor_viewed is null
--                         group by co_r_id) co on
--          co.co_r_id = r.r_id
     where r_d_id = d.d_id and
           r_s_id = s.s_id and
           r_c_id = c.c_id and
           r_t_id = t.t_id and
           r_d_id = d.d_id and
           r_de_id = de.de_id and
           r_u_id = u.u_id;

but I get the error:

[gary@eddie gary]$ psql -f goole1.sql
DROP
psql:goole1.sql:45: ERROR:  Relation "r" does not exist
[gary@eddie gary]$

I tried using the table name instead of the alias but instead got the error:

[gary@eddie gary]$ psql -f goole1.sql
psql:goole1.sql:1: ERROR:  view "nrequest_details" does not exist
psql:goole1.sql:45: NOTICE:  Adding missing FROM-clause entry for table 
"requests"
psql:goole1.sql:45: ERROR:  JOIN/ON clause refers to "requests", which is not 
part of JOIN
[gary@eddie gary]$

which at least makes sense.

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     




view thread (6+ messages)  latest in thread

Message-ID: <200406211110.39940.gary.stainburn@ringways.co.uk>
Permalink:  ../200406211110.39940.gary.stainburn@ringways.co.uk/
Also on:    postgresql.org/message-id/200406211110.39940.gary.stainburn@ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: subselect prob in view
  In-Reply-To: <200406211110.39940.gary.stainburn@ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox