SQL Server front-end (T-SQL)

Second pass (time zones, WINDOW, hashes, MERGE TOP)

The T-SQL that stage 7 left refused, built (D136) - datetimeoffset and AT TIME ZONE, DATE_BUCKET, the WINDOW clause, IGNORE NULLS, shift operators, MERGE TOP, HASHBYTES, COMPRESS, NEWSEQUENTIALID, TYPEPROPERTY, Hijri styles, ALTER TABLE ADD identity, Reduce.

Every item on this page is built in the SQL Server front-end.

Dates and time zones#

  • datetimeoffset keeps its offset. CAST('2024-07-01 12:00 +05:30' AS datetimeoffset), columns and variables of the type, every CONVERT style SQL Server accepts for it (127 gives UTC with Z), DATEPART(TZOFFSET, x), DATENAME(TZOFFSET, x), DATEADD, and DATEDIFF and comparisons on the UTC moment.
  • x AT TIME ZONE 'Pacific Standard Time' with the 144 Windows zone names of sys.time_zone_info, their daylight rules and their history (the table is generated from the Windows registry, which is where SQL Server reads it). A local time in the hour skipped in spring moves forward; one in the hour that comes twice in autumn takes the daylight offset - as SQL Server does. Every zone is covered for 2024 and for 1970-2040.
  • SWITCHOFFSET, TODATETIMEOFFSET (offset as '+05:30' or minutes), DATE_BUCKET (with an origin), CONVERT styles 22, 130 and 131 (the Hijri calendar of Microsoft's Kuwaiti algorithm, Arabic month names for 130) and FORMAT of a time (the .NET TimeSpan formats c, g, G, hh\:mm, ...).

Queries#

  • WINDOW w AS (PARTITION BY ... ORDER BY ...), OVER w and OVER (w ROWS BETWEEN ...).
  • FIRST_VALUE / LAST_VALUE / LAG / LEAD ... IGNORE NULLS (and RESPECT NULLS).
  • a << n, a >> n, and LEFT_SHIFT / RIGHT_SHIFT in the width of the value's type (CAST(-8 AS int) >> 1 is 2147483644).
  • MERGE TOP (n) [PERCENT] (not together with WHEN NOT MATCHED BY SOURCE).

Functions and DDL#

  • HASHBYTES with MD2, MD4, MD5, SHA, SHA1, SHA2_256, SHA2_512, hashing the bytes SQL Server hashes (UTF-16 for nvarchar).
  • COMPRESS / DECOMPRESS: GZIP; for short values the bytes are the ones SQL Server writes. For longer values SQL Server uses another kind of DEFLATE block and the bytes differ, but each side decompresses the other's.
  • NEWSEQUENTIALID() as a column default, TYPEPROPERTY.
  • ALTER TABLE t ADD id int IDENTITY(1, 1) on a table with rows: the rows are numbered in the table's order, as SQL Server numbers them.
  • geometry.Reduce(tolerance) of points and lines.

Still refused#

  • hierarchyid - its binary encoding and a new user type are a stage of their own.
  • STBuffer, BufferWithTolerance, MakeValid, Reduce of a polygon - SQL Server's answers carry the coordinates of its internal grid, which an independent implementation does not reproduce.
  • FORMSOF and NEAR with a distance in CONTAINS.

The answers that differ are listed on Errors and limits.