A .switch( F i , A i : x ;…)


Switch the values of the reference field between the corresponding key values and the referenced records, or, sometimes switch between them in a reverse direction.


A.switch(Fi, Ai:x;…)


The function enables Fi to switch between the corresponding primary key values and the referenced records of Ai; the key value refers to the primary key value of the referenced record in Ai.Take the Attendance table as an example. The employeeID field may store either the corresponding primary key values of employeeID or the referenced records in Employee table. So, the switch() function can be used to switch between the two objects.Use the index table of the foreign key if any, and create one if unavailable.



A sequence.


The key of A. When Ai:x;… is omitted, Fi stores the records of the referenced table Ai. They can be replaced by Ai’s primary key values through the function.

Fi, Ai

When Ai is available, Fi is the reference field of A, which stores corresponding primary key values. The function is used to switch them to the referenced records. The matching condition is that Fi is equal to the primary key value of Ai. Use null to represent a missing record.

Fi, Ai:x

When both parameter Ai and the primary key x are available, get the first record from Ai in which value x is equal to Fi and make it the value of Fi field. If x is #, locate the records directly through the sequence numbers.

Options: (Available for Fi, Ai and Fi, Ai:x)


Delete the records where no value corresponding to F is found during the matching


Perform the inverse operation of @i, which obtains the records that have no value corresponding to F; with the option do not populate F with nulls


If the specified F field value of a specified record in sequence A doesn’t exist in sequence B, generate a record of the same structure as one in B with F field as the primary key

Return value:

The record sequence after going through a reference value switch.







=demo.query("select * from DEPARTMENT").keys(DEPT)




=demo.query("select * from EMPLOYEE where EID < 10")




=demo.query("select * from DEPARTMENT" ).cursor().memory().keys(DEPT)

Return a memory table







A3 is a memory table; the result is the same as above




Switch records of A2 corresponding to "DEPT " to field values




Delete this record if no value corresponding to DEPT is found




Obtain records that have no values corresponding to DEPT








Related functions: