// dialect comparison

SELECT @@VERSION and version() in every SQL dialect

The first thing any support engineer asks for: exact engine and version. Every engine has a one-liner.

Filed under Sessions & admin

The verdict

Trivial everywhere, just five different spellings. If you are branching application logic on the version, prefer the structured sources (SERVERPROPERTY, server_version_num, v$version) over parsing the banner string.

Where they differ

One line each, no shared spelling. The version string contents also differ: some include the OS build, some just the number.

How each engine writes it

SQL Server

SELECT @@VERSION;

One string with edition, version number, OS and architecture. SERVERPROPERTY('ProductVersion') (for example 17.0.4035.5) and SERVERPROPERTY('Edition') give structured fields.

PostgreSQL

SELECT version();

Full banner string. SHOW server_version gives just the number; current_setting('server_version_num') returns it as an integer string such as 180006, which casts cleanly for comparisons.

MySQL

SELECT VERSION();

Just the version number, such as 8.4.11, sometimes with a distribution suffix (8.0.36-0ubuntu0.22.04.1). @@version_comment names the build, and SHOW VARIABLES LIKE 'version%' adds the compile OS and machine.

SQLite

SELECT sqlite_version();

Library version like 3.45.1. PRAGMA compile_options lists build-time flags; sqlite_source_id() the exact source snapshot.

Oracle

SELECT banner FROM v$version;
-- or: SELECT BANNER_FULL FROM v$version;

From 18c on, v$version returns one row and BANNER_FULL adds the release update (Version 23.26.3.0.0); older releases list a row per component. Reading it needs dictionary access such as SELECT_CATALOG_ROLE.

Questions that come up

Why do I need the exact version?

Syntax and behavior differ by release: PostgreSQL INCLUDE since 11, MySQL descending indexes honored since 8.0, SQL Server DROP IF EXISTS since 2016. Version detection avoids runtime errors.

Does version() work while connected?

Yes, all of these are session-local reads with no locking; safe to call any time, including from health checks.

Oracle says table or view does not exist?

You lack SELECT on v$version (it is a dictionary view). Ask for SELECT_CATALOG_ROLE or use the data dictionary alternative product_component_version.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.