T2.4: Uses IRIS-specific Capabilities

Knowledge Review - InterSystems IRIS SQL Specialist

1. Uses SelectMode appropriately (Logical, Display, ODBC)

Key Points

  • SelectMode: Specifies how data is displayed and input - three modes available: Logical (0), ODBC (1), Display (2)
  • Logical mode: Data displayed in internal storage format ($HOROLOG for dates, encoded format for %List)
  • ODBC mode: Data formatted as YYYY-MM-DD hh:mm:ss.fff for compatibility with ODBC/JDBC clients
  • Display mode: Data formatted per locale settings (MM/DD/YYYY hh:mm:ss for American locale)
  • Default is Logical mode; affects both query output and predicate input format

Detailed Notes

Overview

InterSystems SQL uses the SelectMode option to control how data values are displayed in query results and how input values should be formatted in predicates.

  • Available modes: Logical (0), ODBC (1), Display (2)
  • Internal storage: Data is always stored internally in Logical mode

Transformation Methods

SelectMode applies transformations using methods defined in data type classes:

  • LogicalToDisplay()
  • LogicalToOdbc()
  • DisplayToLogical()
  • OdbcToLogical()

Affected Data Types

SelectMode primarily affects:

  • Date, Time, and Timestamp data types
  • %List encoded data

Mode-Specific Display Formats

Logical mode:

  • Dates: $HOROLOG format (integer days from December 31, 1840, comma, seconds since midnight)
  • %List data: $LISTBUILD statements like $lb("White","Green")

ODBC mode:

  • Dates and times: Standardized as YYYY-MM-DD hh:mm:ss.fff
  • Designed for external tool compatibility

Display mode:

  • Dates: Locale-specific formats defined in %SYS.NLS.Format or data type's FORMAT parameter

Input and Output Implications

SelectMode affects both output formatting and input requirements for WHERE clause predicates.

Mismatch example: If DOB is stored in $HOROLOG format and WHERE clause specifies WHERE DOB > 2000-01-01 (ODBC format):

  • SelectMode=ODBC: Returns intended results
  • SelectMode=Display: Generates SQLCODE -146 (unable to convert date input)
  • SelectMode=Logical: Attempts to parse ODBC date as Logical format, returning zero rows

Internal Processing

  • SelectMode is applied to complete expressions, not individual fields
  • Functions and concatenations performed on Logical representations before SelectMode formatting
  • SQL statements run internally in Logical mode regardless of SelectMode
  • ORDER BY clauses, functions, and SQLPROC methods all operate on Logical values

Setting SelectMode in Dynamic SQL

With %SQL.Statement, SelectMode is set via the %SelectMode property:

  • Example: `##class(%SQL.Statement).%New(2,"Sample")` sets Display mode with Sample schema

Documentation References

2. Uses arrow syntax for implicit joining (->)

Key Points

  • Arrow syntax (->): InterSystems-specific operator for implicit LEFT OUTER JOIN without explicit JOIN syntax
  • Works with reference properties (foreign key relationships) and relationship properties of parent tables
  • Property reference: EmployeeTable->CompanyID->CompanyName traverses related tables seamlessly
  • Child table reference: OrdersTable->LineItems->Amount retrieves child table data with multiple result rows
  • Requires SELECT privileges on both ID field and referenced column in related table

Detailed Notes

Overview

InterSystems SQL provides the arrow syntax operator (->) as a powerful shorthand for accessing values from related tables without writing complex explicit JOIN statements.

  • Operation type: Performs a LEFT OUTER JOIN operation
  • Use cases: Reference properties (column contains ID of referenced table) or relationship properties of parent tables
  • Limitations: Cannot be used in ON clauses or with all foreign key types

Basic Usage

The arrow operator allows intuitive navigation across table relationships similar to object dot notation.

Example comparison:

  • Explicit JOIN: `SELECT Sample.Employee.Name, Sample.Company.Name FROM Sample.Employee LEFT OUTER JOIN Sample.Company ON Sample.Employee.Company = Sample.Company.ID`
  • Arrow syntax: `SELECT Name, Company->Name FROM Sample.Employee`

Valid Placement

Arrow operator can be used anywhere a column expression is valid:

  • SELECT lists
  • WHERE clauses
  • GROUP BY clauses
  • ORDER BY clauses

Compound Arrow Syntax

Supported for traversing multiple relationships:

  • Example: `Film->Category->CategoryName` accesses three related tables in sequence

Child Table References

When referencing child tables:

  • Arrow syntax produces multiple rows in the result set for each parent row
  • Example: `SELECT LineItems->amount FROM Orders` is equivalent to `SELECT L.amount FROM Orders O LEFT JOIN LineItems L ON O.id=L.custorder`

Privilege Requirements

Arrow syntax requires appropriate SELECT privileges on all referenced data.

With column-level privileges:

  • Need SELECT privilege on both the ID field of the referenced table and the referenced column
  • Example: `Company->Name` requires privileges on Company.ID and Company.Name

Compatibility

  • Can be combined with explicit JOIN syntax in the same query
  • Works with sharded tables

Exam Preparation Summary

Critical Concepts to Master:

  1. Three SelectMode Options: Know when to use Logical (0), ODBC (1), or Display (2) modes
  2. SelectMode Data Type Impact: Understand how dates/times and %List data display differently in each mode
  3. SelectMode Input/Output: Recognize that SelectMode affects both query output formatting and WHERE clause input requirements
  4. Arrow Syntax Basics: Master the -> operator for implicit LEFT OUTER JOIN operations
  5. Compound Arrow Syntax: Understand chaining multiple arrows for multi-table traversal
  6. Arrow Syntax Privileges: Know that SELECT privileges required on both ID and referenced columns

Common Exam Scenarios:

  • Choosing appropriate SelectMode for ODBC/JDBC client applications vs. internal queries
  • Troubleshooting date comparison errors caused by SelectMode mismatches
  • Simplifying complex JOIN queries using arrow syntax
  • Using arrow syntax in WHERE, GROUP BY, and ORDER BY clauses
  • Understanding privilege requirements for arrow syntax queries
  • Recognizing when arrow syntax cannot be used (ON clauses, certain foreign key types)

Hands-On Practice Recommendations:

  • Execute the same query with different SelectMode settings and compare results
  • Practice converting explicit LEFT OUTER JOIN queries to arrow syntax
  • Test compound arrow syntax with multi-level table relationships
  • Verify arrow syntax privilege requirements with %CHECKPRIV
  • Use arrow syntax with child tables to understand result set multiplication
  • Combine arrow syntax with explicit JOINs in complex queries

Report an Issue