4

I created a materialized view for my flask web application with the help of Jeff Widman.

Unfortunately he only describe how to join two tables. I would like to create a materialized view with more than two tables.

class AnalyticV(MaterializedView):
  __table__ = create_mat_view("my_view",
                             db.select([Table1.id.label('id'),
                                        Table1.title.label('title'),
                                        Table2.location.label('loc'),
                                        Table3.time.label('time'),]
                             ).select_from(db.join(Table1, Table2, isouter=True) )
                             )

How can I insert a second

select_from(db.join(Table1, Table3, isouter=True))

Table1 has two relationships to Table2 and Table3

The SQL should look like this:

SELECT Table1.id AS id,
       Table1.title AS title,
       Table2.location AS loc,
       Table3.time AS time 
FROM Table1 LEFT OUTER JOIN Table2 ON Table2.id = Table1.table2_id
LEFT OUTER JOIN Table3 ON Table3.id = Table1.table3_id
2
  • Glad to know my blog post was useful! Commented May 10, 2017 at 21:27
  • db.select() !!! Fantastic! +1 Commented Feb 17, 2020 at 20:08

1 Answer 1

2

Just add another join

select_from(db.join(Table1, Table2, isouter=True).join(Table3, isouter=True)) 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! I always tried it with db.join(Table1, Table2).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.