query_script_flow_control

SYNOPSIS

QueryScript Flow Control: conditional execution via looping & branching.

QueryScript supports the following flow control structures:

And the following flow control statements :

  • break: leave executing loop
  • return: quit script execution

DESCRIPTION

The flow control structures are similar in nature to those of other common programming language. Flow control works by evaluation an expression. The truth value of the expression determines whether code will branch, loop, break, etc.

EXAMPLES

Rebuild partitions for all NDB tables:

foreach($table, $schema, $engine: table like '%')
  if ($engine = 'ndbcluster')
    ALTER ONLINE TABLE :$schema.:$table REORGANIZE PARTITION;

Throttle deletion of rows:

while (DELETE FROM world.Country WHERE Continent = 'Asia' LIMIT 10)
{
  -- We remove 10 rows at a time, and throttle by waiting in between 
  -- deletions twice the amount of time executed on deletion.
  throttle 2;
}

Create or upgrade a table

try
{
  -- Try and create table:
  CREATE TABLE test.article (
    article_id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    title varchar(128) CHARSET utf8,
    content text CHARSET utf8
  );
}
catch
{
  -- Apparently table already exists. Upgrade it:
  ALTER TABLE test.article
    MODIFY COLUMN content text CHARSET utf8;
}


 
common_schema documentation