Description:
Generate multiple records based on a record sequence, concatenate them into a new table sequence and return it to the original cursor.
Syntax:
cs.news(X;xi:Fi,…)
Note:
The function attaches a computation to cursor cs, which computes expression xi on record sequence X , makes the results values of the new field Fi, and generates multiple records to form a new table sequence, and returns the table sequence to the original cursor cs.
This is a delayed function.
Parameter:
cs |
A cursor |
X |
Record sequence |
xi |
An expression, whose values are uses as the new field values. It is treated as null if omitted; in that case, : Fi can’t be omitted. The sign # is used to represent a field with a sequence number |
Fi |
Filed name of the new cs; use the identifiers parsed from expression xi if it is omitted |
Option:
@1 |
Left join, which creates an empty record when record sequence X is empty |
Return value:
Cursor
Example:
|
A |
|
1 |
=demo.cursor("select EID,NAME,DEPT,GENDER,BIRTHDAY,SALARY from EMPLOYEE") |
Return a cursor.
|
2 |
=demo.query("select EID,NAME,DEPT,GENDER,BIRTHDAY,SALARY from EMPLOYEE") |
Return a table sequence:
|
3 |
=A2.group(GENDER;~:gup) |
Group table sequence A2 by GENDER field and return result set as follows:
|
4 |
=A1.groupx(GENDER;avg(SALARY):avg) |
Group cursor A1 by GENDER field, compute average SALARY value in each group and return a cursor; below is data in the result cursor:
|
5 |
=A4.join(GENDER,A3:GENDER,gup) |
Attach a computation to cursor A4, which performs foreign key join with A3 and return the original cursor A4; below is the data of cursor A4 where A5’s computation is executed:
|
6 |
=A4.news(gup;EID,#2:Lname,GENDER,age(~.BIRTHDAY):Age,SALARY+50: Salary,avg:AvgSalary) |
Attach a computation to cursor A4 to compute gup field values, renames the 2nd field Lname using expression #2:Lname, form a table sequence consisting of EID, Lname, GENDER, Age, Salary and AvgSalary to return cursor A4, and returns the original cursor. |
7 |
=A4.fetch() |
Fetch data from cursor A4 where A6’s computation is executed (it would be better to fetch data in batches when a huge amount of data is involved):
|
When @1 option works:
|
A |
|
1 |
=demo.cursor("select EID,NAME,DEPT,GENDER,BIRTHDAY,SALARY from EMPLOYEE") |
Return a cursor.
|
2 |
=demo.query("select EID,NAME,DEPT,GENDER,BIRTHDAY,SALARY from EMPLOYEE where GENDER='M' ") |
Return a table sequence:
|
3 |
=A2.group(GENDER;~:gup) |
Group table sequence A2 by GENDER field and return result set as follows:
|
4 |
=A1.groupx(GENDER;avg(SALARY):avg) |
Group cursor A1 by GENDER field, compute average SALARY value in each group and return a cursor; below is data in the result curso
|
5 |
=A4.join(GENDER,A3:GENDER,gup) |
Attach a computation to cursor A4, which performs foreign key join with A3 and returns the original cursor A4; below is data in cursor A4 where the attached computation is executed:
|
6 |
=A4.news@1(gup;EID,NAME,GENDER,age(~.BIRTHDAY):Age,Salary,avg:AvgSalary) |
Attach a computation to cursor A4 to compute gup field values, form a table sequence consisting of EID, NAME, GENDER, Age, Salary and AvgSalary to return cursor A4, and returns the original cursor. @1 option enables left join to create an empty record when the corresponding record in record sequence X is empty. |
7 |
=A4.fetch() |
Fetch data from cursor A4 where A6’s computation is executed; below is the result set:
|
Related functions:
A.news(X;xi:Fi,…)