DISPLAY YUGABYTEDB VERSION (WITH YB_VERSION)

The version() built-in function returns both the supported PostgreSQL version and the version of YugabyteDB.

If you are just interested in the YugabyteDB version, you can easily extract that info using the SUBSTRING function with a regular expression.

				
					yugabyte=# SELECT version() AS "PostgreSQL and YugabyteDB Version";
                                                                            PostgreSQL and YugabyteDB Version
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 11.2-YB-2.13.2.0-b0 on x86_64-pc-linux-gnu, compiled by clang version 12.0.1 (https://github.com/yugabyte/llvm-project.git bdb147e675d8c87cee72cc1f87c4b82855977d94), 64-bit
(1 row)

yugabyte=# SELECT substring(version() from 'YB-([^\s]+)') AS "YugabyteDB Version";
 YugabyteDB Version
--------------------
 2.13.2.0-b0
(1 row)
				
			

So that you don’t have to remember that SUBSTRING command, you can encapsulate the logic into a function!

				
					CREATE OR REPLACE FUNCTION yb_version() RETURNS VARCHAR
AS
$$
BEGIN
   RETURN substring(version() from 'YB-([^\s]+)');
END;
$$ language 'plpgsql';
				
			

Example:

				
					yugabyte=# CREATE OR REPLACE FUNCTION yb_version() RETURNS VARCHAR
yugabyte-# AS
yugabyte-# $$
yugabyte$# BEGIN
yugabyte$#   RETURN substring(version() from 'YB-([^\s]+)');
yugabyte$# END;
yugabyte$# $$ language 'plpgsql';
CREATE FUNCTION

yugabyte=# SELECT yb_version();
2.13.2.0-b0
				
			

Update 04/07/2024: Function re-written to use SQL language per the reasoning detailed in the post GENERATE A RANDOM STRING (FASTER METHOD).

				
					CREATE OR REPLACE FUNCTION yb_version() RETURNS VARCHAR
AS
$$
   SELECT substring(version() from 'YB-([^\s]+)');
$$ language 'sql';
				
			

Have Fun!