Define a field value switching operation on a pseudo table and return a new pseudo table.
Syntax:
T.switch(Fi,Ai:x;…)
Note:
The function defines a computation on pseudo table T, which will replace values of Fi field in pseudo table T with corresponding values in table sequence/record sequence Ai by matching the Fi value with parameter x, which is the primary key or logical primary key of Ai and returns a new pseudo table. By default, an Fi field value displays as empty when no record in Ai matches it.
Parameter:
T |
A pseudo table |
Fi |
A pseudo table field |
Ai |
A table sequence/record sequence |
x |
The primary key or logical key of Ai; the parameter can be omitted if primary key is already set for Ai |
Option:
@i |
If no value corresponding to F is found, remove the pseudo table record |
@d |
Perform the inverse operation of @i to obtain pseudo table records that have no matching value in Ai for F field |
@1 |
If the F field value of a pseudo table record doesn’t exist in Ai, then generate a record of the same structure as Ai with expression x being the primary key |
Return value:
Pseudo table
Example:
|
A |
B |
|
1 |
=create(file).record(["emp_news.ctx"]) |
|
Below is content of composite table emp_news.ctx:
|
2 |
=pseudo(A1) |
|
Generate a pseudo table from the composite table. |
3 |
=demo.query("SELECT top 4 * FROM DEPARTMENT").keys(DEPT) |
|
Return a table sequence and set DEPT field as its primary key:
|
4 |
=A2.switch(DEPT,A3) |
=A4.import() |
Execute expression in A4 to define a computation on A2’s pseudo table, which will convert its DEPT field values into corresponding referencing field values in table sequence A3, and retrun a new pseudo table. Execute expression in B4: import data from A4’s pseudo table while executing the computation deinfed in A4 on A2’s pseudo table, and return the following table:
|
5 |
=A2.switch@i(DEPT,A3) |
=A5.import() |
Use @i option to delete pseudo table records that can’t be matched; execute B5 and return the following table:
|
6 |
=A2.switch@d(DEPT,A3) |
=A6.cursor().fetch() |
Use @d option to retain only the non-matching records in the pseudo table; execute B6 and return the following table:
|
7 |
=A7.cursor().fetch() |
Use @1 option to generate a record having same structure as table sequence A3 when a DEPT value of the pseudo table does not have a match in A3 and using DEPT as the primary key; execute B7 and return the following table:
|