SQL for Branch Versioned LRS Data

667
2
03-30-2023 08:25 PM
AyanPalit
Esri Regular Contributor
2 2 667

Data leads and DBA's rely on SQL to query data. Data analysts unversed with LRS and/or versioning may struggle with query methods. 

Note that there are 2 technical concepts in play:

  • Branch Versioning (more fundamental geodatabase concept)
  • ArcGIS Roads and Highways
    • Time Awareness: FROMDATE/ TODATE fields (R&H specific and applies to Routes and Events only)
    • Location Error: LOCATIONERROR field (R&H specific and applies to Events only)

 The design considerations are discussed in the blog SQL Views and Branch Versioning

The following SQL code logic may be used to build queries off branch-versioned LRS datasets:

SELECT Name, Type                       -- Attributes
FROM GIS.ROAD_XX t                      -- Table
WHERE t.gdb_is_delete = 0               -- Start branch versioning logic
AND t.gdb_branch_id = 0
AND t.gdb_archive_oid = ( SELECT MAX(gdb_archive_oid)
                          FROM  <table> bt
                          WHERE bt.globalID = t.globalID
                          AND   bt.gdb_branch_id = 0 )	
                                        -- End branch versioning logic
-- Optional LRS filtering
AND TODATE IS NULL			-- Current LRS records   
AND LOCATIONERROR = ‘NO ERROR’	        -- Event records with no LRS errors

 

 

2 Comments
About the Author
Principal Consultant @Esri with over 20 years of GIS experience in the Energy and Utilities verticals.