Using Session Variables

YugabyteDB lets you declare session variables and use them in a YSQL statement or stored procedure.

Example:

				
					yugabyte=# SELECT * FROM test_schema.test_table;
 c1 | c2 | c3
----+----+----
  1 | A  | Z
  2 | B  | Y
  3 | C  | X
(3 rows)

yugabyte=# SET myscope.c1 = 1;
SET

yugabyte=# SET myscope.c3 = 'Z';
SET

yugabyte=# SHOW myscope.c1;
 myscope.c1
------------
 1
(1 row)

yugabyte=# SHOW myscope.c3;
 myscope.c3
------------
 Z
(1 row)

yugabyte=# SELECT * FROM test_schema.test_table WHERE c1 = current_setting('myscope.c1')::INT AND c3 = current_setting('myscope.c3');
 c1 | c2 | c3
----+----+----
  1 | A  | Z
(1 row)
				
			

Have Fun!