Wildcard Rules in StreamSQL SELECT Statements

Wildcard rules in a StreamSQL SELECT statement are a convenient shorthand method to select all the fields from a stream or connected data source. The SELECT Statement topic included an introduction to wildcard rules, whose general syntax is:

wildcard_expression [AS wildcard_target]

This topic provides more details about wildcard rule semantics, and some examples.

Note

In StreamBase 5.1, wildcard rules can contain only simple wildcard expressions like * and f(*). In future releases, more complex selections (including multiple wildcard expressions) will be allowed.

Wildcard Rule Expansion

A wildcard rule expands to a standard (non-wildcard) rule that contains one entry for each field in the wildcard rule's context. That is, the asterisk (*) token in the wildcard expression and wildcard target is replaced with a field name in the referenced stream.

Example 1.

CREATE INPUT STREAM FOO (x int, y int, z int);
SELECT f(*) AS f_* FROM foo INTO bar;

Expands to:

CREATE INPUT STREAM FOO (x int, y int, z int);
SELECT f(x) AS f_x, f(y) AS f_y, f(z) AS f_z FROM foo INTO bar;

Notice in this example:

  • The wildcards in the expression and target select all the fields in the input stream.

  • The expanded target list contains multiple, comma-separated target list items, one for each field that the expression selected. The expanded list items are standard rules.


Example 2.

In this example, we use a wildcard to pass arguments to a function:

CREATE INPUT STREAM foo (x int, y int, z int);
SELECT abs(*) AS * FROM foo INTO bar;

Expands to:

CREATE INPUT STREAM foo (x int, y int, z int);
SELECT abs(x) AS x, abs(y) AS y, abs(z) AS z FROM foo INTO bar;

Example 3.

This example demonstrates the implicit wildcard target, where we omit the AS keyword and target:

CREATE INPUT STREAM foo (x int, y int, z int);
SELECT f(*) FROM foo INTO bar;

Expands to:

CREATE INPUT STREAM foo (x int, y int, z int);
SELECT f(x) AS x, f(y) AS y, f(z) AS z 
  FROM foo INTO bar;

Notice how the expansion automatically creates targets by default.