mercredi 22 juillet 2015

How to overcome SQLite View limitation

Given that in SQLite, Views:

  • are read-only
  • cannot be UPDATEd,

the following is the situation:

There are 4 tables A, B, C and D and a View has to be created with data from all the four tables conditionally. Here's the pseudo-construct:

CREATE VIEW AS E SELECT A.A1, A.A2, A.A3, A.A4, B.B1, C.C1, C.C2, D.D1, D.D2 FROM A, B, C, D
WHERE A.X = 'SOME STRING' AND
    A.FK = C.PK AND
    A.Y = B.Z AND 
    D.G = A.PK AND
    D.H = 'SOME STRING'

The requirement is that, irrespective of no matches in D, the remaining matches should get populated, (with 0 values in the view E for the columns from D). Needless to say, the above construct works if there are matching D rows, but obviously returns an empty view if there are no D matches.

How can the CASE statement or SELECT sub-queries (or an altogether different construct, like an INSTEAD OF trigger) deliver this requirement?

Greatly appreciate if the database experts could publish the exact construct(s). Many, many thanks in advance!

Aucun commentaire:

Enregistrer un commentaire