YoungStudent
YoungStudent

Reputation: 71

Creating view with join

I have tried to create view type_of_the_house_view but it doesn't work. What could be the matter?

// the code is written on PostgreSQL

  create view real_property_and_seller_view
    as select (real_property.seller_id,
                     house_id,
                     cost,
                     floor,
                     square,
           surname,
           name,
           phone_number)
     from real_property left join seller
 on (real_property.seller_id = seller.seller_id);

Upvotes: 2

Views: 99

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269553

You are over-using parentheses:

create view real_property_and_seller_view as
    select rp.seller_id, house_id, cost, floor, square,
           surname, name, phone_number
    from real_property rp left join
         seller s
         on rp.seller_id = s.seller_id;

You should also qualify all column names in the referenced in the query. I might guess:

create view real_property_and_seller_view as
    select rp.seller_id, rp.house_id, rp.cost, rp.floor, rp.square,
           s.surname, s.name, s.phone_number
    from real_property rp left join
         seller s
         on rp.seller_id = s.seller_id;

The error is a little hard to explain. When you use parentheses, the columns create a tuple, which is also called a record in Postgres. This is not allowed for a view.

Upvotes: 1

Related Questions