Skip to main content

SQL dialect gotchas

Interviewers rarely fail you for dialect syntax. But in real work, and in take-homes on a specific warehouse, a few differences silently change results. These are the ones worth knowing. Each one links to the vendor documentation, because defaults change between versions.

The playground runs DuckDB, which behaves like PostgreSQL in most of these cases.

Changes your results​

GotchaWhat happensDocs
Integer divisionSQL Server: 5 / 2 = 2 (integer). BigQuery: / returns FLOAT64 (2.5); use DIV for integers. Snowflake: returns a decimal with extra scale (2.500000).SQL Server · BigQuery · Snowflake
Default NULL sort orderSnowflake: NULLs sort last in ascending order (configurable with DEFAULT_NULL_ORDERING). BigQuery and SQL Server: NULLs are lowest, so first in ascending order. Changes ORDER BY … LIMIT and ROW_NUMBER results. Write NULLS FIRST/LAST explicitly where supported.Snowflake · BigQuery
Week startBigQuery DATE_TRUNC(d, WEEK) starts on Sunday; use WEEK(MONDAY) or ISOWEEK. Snowflake depends on the WEEK_START parameter.BigQuery · Snowflake
DATEDIFF counts boundariesSnowflake and SQL Server DATEDIFF(minute, a, b) count minute boundaries crossed, not elapsed minutes. 10:00:59 to 10:01:00 is "1 minute". Use seconds and divide.Snowflake · SQL Server
Case-sensitive comparisonsSQL Server's default collations are case-insensitive ('A' = 'a'); Snowflake compares case-sensitively by default. Joins and GROUP BYs on text change.SQL Server
Timestamp typesBigQuery TIMESTAMP is an absolute instant (UTC); DATETIME has no time zone. Snowflake has TIMESTAMP_NTZ, _LTZ and _TZ, and plain TIMESTAMP maps to one of them by setting.BigQuery · Snowflake

Syntax that won't run elsewhere​

GotchaDifferenceDocs
Row limitsSQL Server uses TOP n or OFFSET … FETCH, not LIMIT.SQL Server
String concatenationSQL Server uses + (or CONCAT); most others use ||. With +, a NULL makes the whole result NULL.SQL Server
BooleansSQL Server has no boolean column type; use BIT and compare = 1.SQL Server
GROUP BY alias or positionSQL Server doesn't allow GROUP BY 1 or a SELECT alias; repeat the expression.SQL Server
QUALIFYSnowflake, BigQuery and Databricks support it; SQL Server doesn't (use a CTE).Snowflake · BigQuery · Databricks
DATE_TRUNC argument orderBigQuery: DATE_TRUNC(d, MONTH). Snowflake and Databricks: DATE_TRUNC('MONTH', d). SQL Server 2022+: DATETRUNC(month, d).BigQuery · SQL Server
Recursive CTEsSQL Server omits the RECURSIVE keyword; BigQuery requires it.SQL Server · BigQuery
Identifier caseSnowflake uppercases unquoted identifiers; "orderId" and orderid are different columns.Snowflake

Teradata​

Teradata notes are being reviewed and will be added with sources. Many migration projects start from Teradata, so this section is a priority.

Practice​

Most SQL questions in the bank include dialect notes with sources. Open a question's solution to see them.