T .insert()

Description:

Insert one or more records into a table sequence.

Syntax:

T.insert(k)

Insert an empty record before the position k in the T. If k is 0, then append it in the end and return the new T

T.insert(k,xi:Fi,…)

Insert a record into T before the position k where the value of Fi is xi and return the new T. When parameter k is omitted, we assume the table sequence T is already ordered by the key and insert records; if the key value has already existed, the function won’t perform the insertion.

T.insert(k:A,xi:Fi,…)

Insert multiple records into T before the position k where the value of Fi is xi and return the new T . The number of the records to be inserted is determined by the length of sequence A.

Note:

The function inserts one or more records into the table sequence T, and automatically updates the index, if any, and checks distinctness.

Parameters:

k

The position before which the member, or the record, is inserted. When k==0, append it in the end.

xi

The Fi field value before which the new record is to be inserted

Fi

The name of field where xi resides; without Fi, it will be the corresponding ith field.

T

A table sequence

A

A sequence or an integer; if A is an integer, then it is equal to to(A)

Options:

@n

Return the inserted record or a record sequence of the inserted records

@r(k:A)

Insert sequence A into table squence T from the kth record according to the order of the fields

@f(k:A)

Insert sequence A into table squence T from the kth record; only the common fields are inserted.

Return value:

The table sequence T into which you have inserted new records

Example:

 

A

 

1

=create(id,name,age)

Construct an empty table sequence

 

2

=A1.insert(0,1,"Jack",29)

Append a record whose field values are 1,Jack, and 29

 

3

=A1.insert(1,2,"Lucy",30)

Add a record before the first record whose values are 2, Lucy, and 30.

 

4

=A1.insert(0)

Append an empty record in the end.

 

5

=A1.insert(0:3)

Append three empty records in the end.

 

6

=A1.insert@n(1:1,10,"Lily",30)

 Return the inserted record

7

=create(ID,Name,Age)

 

8

=A7.insert(0:A1,id:ID,name:Name,age:Age)

Add the records of A1 into A7 one by one.

 
 

9

=A1.delete(A1.select(id<2))

 

10

=A7.insert@r(5:A9)

Insert A9 into A7 from the fifth record

11

=create(ID,Name,AGE)

 

12

=A11.insert@f(3:A7)

Insert only the ID and Name fields of A7 to A11 from the third record

13

=A1.keys(id)

Set id as A1’s primary key, then A1’s data is as follows:

14

=A1.insert(,5,"Mary",28)

Parameter k is omitted; assume A1 is already ordered by id and insert the records

15

=A1.insert(,2,"CC",32)

Same result as A14; since the record where the key value is 2 already exists, the function cancels the insertion

16

=file("D:\\test.txt").import@t()

test.txt defines only the column headers

17

=A16.insert(0,1,"2008-8-4")

Insert a record

Related functions:

T.modify()

T.delete()

A.insert()