Maintenance of Table Sequences & Record Sequences

This chapter lists code examples of handling data maintenance in table sequences and record sequences, including Copy a table sequence entirely, Insert one or multiple null or non-null records into a table sequence, Remove one or multiple records from a table sequence, Modify field values of one or multiple records, Modify the record at a specified position and fill up the position automatically if it is beyond range, Add a calculated column to a table sequence, Create a new table sequence based on the specified table sequence/record sequence, Combine table sequences or split a table sequence, Insert a sequence into the newly-created table sequence to generate new records, Get field values of a table sequence/record sequence and join them into a sequence, Add sequence members into a table sequence/record sequence as field values, Add sequence members to a table sequence/record sequence vertivally as field values, Copy field values of a table sequence/record sequence into another table sequence/record sequence, and Modify values of specified field.

Copy a table sequence entirely

 

A

 

1

=demo.query("select NAME,EVENT, SCORE from GYMSCORE")

 

2

=A1.derive()

Copy the table sequence entirely

3

=A1.to(,)

Copy as a record sequence only

 

Insert record(s) to Tseq at specified position

 

A

 

1

=create(ID,NAME,AGE)

Create an empty table sequence

2

>A1.insert(0,10,"Lucy",20)

Insert a record at the end

3

>A1.insert(1,1,"Jim",19)

Insert a record at the first row

4

>A1.insert(2:8,#+1,"Name"+string(#+1),rand(4)+18)

Insert eight records starting from the second row

5

=create(id,NAME,Age)

Create an empty table sequence

6

>A5.insert(0:5,#+10,"Name"+string(#+10),rand(4)+18)

Insert 5 records at the end

7

=A1.insert@r(0:A5)

Insert A5’s records to A1

8

=A1.insert@f(0:A5)

Insert namesake fields in A5 to A1

9

>A1.insert(2)

Insert an empty record before the second row

10

>A1.insert(0:10,~:ID)

Append 10 records at the end and set ID field values

 

Remove one or multiple records from a table sequence

 

A

 

1

=demo.query("select NAME, EVENT, SCORE from GYMSCORE")

 

2

>A1.delete(2)

Remove the second record

3

>A1.delete([4,6,1])

Remove multiple records

4

>A1.delete(A1.select(SCORE<15))

Remove records based on specified conditions

 

Modify field values of one or multiple records

 

A

 

1

=demo.query("select NAME,EVENT, SCORE from GYMSCORE")

 

2

>A1.run(SCORE+2:SCORE)

Modify all the records

3

>A1.select(EVENT=="Vault").run(SCORE+2:SCORE)

Modify some of the records

 

Modify a record at a specified position and fill up the position automatically if the record is beyond range

 

A

 

1

=demo.query("select NAME,EVENT, SCORE from GYMSCORE")

A table sequence

2

=A1.modify(5,"":EVENT,15:SCORE)

Modify the fifth record and fill up the out-of-range positions automatically

 

Add a calculated column to a table sequence

 

A

 

1

=demo.query("select NAME,UNITPRICE, QUANTITY from RECEIPT")

 

2

=A1.derive(UNITPRICE*QUANTITY:Amount)

Add the "Amount" field

 

Create a new table sequence based on the specified table sequence/record sequence

 

A

 

1

=demo.query("select NAME, ABBR, CAPITAL,POPULATION from STATES")

 

2

=A1.new(NAME, ABBR)

Create a new table sequence based on the original one

3

=A1.new(NAME:State, ABBR,CAPITAL:Capital)

Change the field names

 

Combine table sequences or split a table sequence

 

A

 

1

=demo.query("select * from STUDENTS1")

 

2

=demo.query("select * from STUDENTS2 ")

 

3

=A1|A2

Concatenate table sequences A1 and A2

 

Insert a sequence into the newly-created table sequence to generate new records

 

A

B

 

1

1

Tom

 

2

2

Jack

 

3

3

Andy

 

4

=create(id,name)

 

 

5

=A4.record([A1:B3])

 

 

 

Get field values of a table sequence / record sequence and join them into a sequence

 

A

B

 

1

1

Tom

 

2

2

Jack

 

3

3

Andy

 

4

=create(id,name)

 

 

5

=A4.record([A1:B3])

 

 

6

=A5.field(2)

 

Return the same sequence as [B1:B3]

 

Add sequence members into a table sequence / record sequence as field values

 

A

B

 

1

1

Tom

 

2

2

Jack

 

3

3

Andy

 

4

=create(id, name).insert(1:3)

 

 

5

=A4.paste@a([A1:B3])

 

 

 

Add sequence members to a table sequence / record sequence vertically as field values

 

A

B

C

 

1

1

2

3

 

2

Tom

Jack

Andy

 

3

=create(id, name).insert(1:3)

 

 

 

4

=A3.modify(1:[A1:C1],~:#1)

 

 

The first column

5

=A3.modify(1:[A2:C2],~:#2)

 

 

The second column

 

Copy field values of a table sequence/record sequence into another table sequence/record sequence

 

A

 

1

=create(name,price)

 

2

=demo.query("select NAME,UNITPRICE, QUANTITY from RECEIPT")

 

3

=A1.modify@r(0:A2)

 

 

Modify values of specified field

 

A

 

1

=demo.query("select * from EMPLOYEE")

 

2

=A1.field("SALARY",[8000,9000])

Modify the first two values of SALARY field

3

=A1.field(9,[8000,9000])

Modify the first two values of the 9th field