Advanced

Dynamic attrs

We can use attrs for other things as well.

Dynamic projections

For example, projecting from a dynamically generated list of attributes. If we want to project the attributes of S that are of type int, say, then we could:

S{attrs(heading(S)[type="int"])}
STATUS
10
20
30

Or if we want to project the attributes of S that are not of type int then we could:

S~{attrs(heading(S)[type="int"])}
SNOSNAMECITY
S1SmithLondon
S2JonesParis
S3BlakeParis
S4ClarkLondon
S5AdamsAthens

Dynamic variables

We can also pass attrs to schema, which lets us select variables from the current schema (schema giving us a single tuple containing an attr/value for each entry in the schema). If we want to get the variable named S, say, then we could:

schema{attrs(dee(attr:="S"))}.*
SNOSNAMESTATUSCITY
S1Smith20London
S2Jones10Paris
S3Blake30Paris
S4Clark20London
S5Adams30Athens

Where you'll notice the S we selected was passed as a string and evaluated by attrs at runtime.

Dynamic everything

And of course we can have a dynamic projection on a dynamically chosen relvar:

schema{attrs(dee(attr:="S"))}.*{attrs(heading(schema{attrs(dee(attr:="S"))}.*)[type="int"])}
STATUS
10
20
30