keys()

Read(1877) Label: table sequence, set a key,

Here’s how to use keys() function.

T.k eys()

Description:

Set a key for a table sequence.

Syntax:

T.keys(Ki,…)

Note:

The function sets Ki,… as the key of the table sequence T. The absence of the parameter will clear the key. A T.create() operation will copy the key at the same time.

Parameter:

T

A table sequence.

Ki

Key name.

Option:

@t(…,KT)

Set the last parameter KT as the time key, and make all other parameters the basic keys.

Return value:

Table sequence

Example:

 

A

 

1

=demo.query("select EID,NAME,DEPT,SALARY,HIREDATE from EMPLOYEE order by EID asc,DEPT asc")

 

2

=A1.keys(EID,DEPT)

Set EID&DEPT fields as A1’s key.

3

=A1(1).key()

[1,R&D].

4

=A1.keys()

Remove the key.

5

=A1(1).key()

Return null because A1 doesn’t set a key.

6

=A1.keys@t(EID,DEPT,HIREDATE)

Set EID and DEPT as A1’s basic keys and HIREDATE as time key.

7

=A1.create()

Copy the key since table sequence T has one.

8

=A7.insert(0,1,"Jack","HR",3000,date("2022-03-09"))

9

=A8(1).key()

[1,HR]; here values of basic keys are returned.

Related functions:

r.key()

v.v()

T.keys( Ki,… )

Description:

Define the key(s) for an in-memory table.

Syntax:

T.keys(Ki,…)

Note:

The function defines key(s) Ki,…, which may include the time key, for in-memory table T.

Parameter:

Ki

Key name; can be one or multiple keys; delete all keys of an in-memory table when the parameter is absent

T

An in-memory table

Optios:

@t(…,KT)

Set the last parameter KT as the time key and all other key fields constitute the basic key

Return value:

An in-memory table

Example:

 

A

 

1

=demo.cursor("select EID,NAME,GENDER from EMPLOYEE where EID<10")

Return cursor of the retrieved data.

2

=A1.memory()

Return an in-memory table:

3

=A2.keys(EID,NAME)

Set EID and NAME as the in-memory table’s keys.

4

=A3(1).key()

Get the keys of the first record and return the result:

5

=A2.keys()

Delete all keys of the in-memory table.

6

=A3(1).key()

Query the keys of the first record and return null.

7

=demo.cursor("select * from employee").memory()

Return an in-memory table.

8

=A7.keys@t(EID,HIREDATE)

Set EID as the basic key and HIREDATE as the time key in A7’s in-memory table.

T.keys@i(Ki, … ;n)

Description:

Set primary key for a table sequence or an in-memory table and create index for the table at the same time.

Syntax:

T.keys@i(Ki,…;n) 

Note:

The function sets primary key Ki,... for table sequence/in-memory table T and, in the meantime, creates an index over the key. Create hash index when the function only works with @i option. 

Parameter:

Ki

Primary key, which can be one or multiple; delete all keys of T when this parameter is absent

T

A table sequence/in-memory table

n

An integer greater than 1, which is length of the hash table; its default length is the table length; cannot create a serial byte index when this parameter is present

Option:

@s

Create a serial byte index for a serial byte primary key; omit parameter n when using this option

@m

Enable parallel processing to create the index

@t

Set the last Ki parameter as the time key and create index on it

@n

Create an ordinal number key

Return value:

A table sequence/in-memory table

Example:

Set key for a table sequence and create hash index:

 

A

 

1

=demo.query("select EID,NAME,DEPT,SALARY from EMPLOYEE")

 

2

=A1.keys@i(EID,DEPT;5)

Set EID and DEPT as the key of A1’s table sequence and create a hash index whose size is 5.

3

=A1.keys@im(EID,NAME)

Create index using parallel processing.

Set key for an in-memory table and create hash index:

 

A

 

1

=demo.cursor("select EID,NAME,DEPT,SALARY,HIREDATE from EMPLOYEE").memory()

 

2

=A1.keys@i(EID,DEPT;5)

Set EID and DEPT as the key of A1’s in-memory table and create a hash index whose size is 5.

3

=A1.keys@im(EID,NAME)

Create index using parallel processing.

Create indexes of others types:

 

A

 

1

=demo.query("select EID,NAME,DEPT,SALARY,HIREDATE from EMPLOYEE")

 

2

=A1.keys@in(EID)

Set EID as the key of A1’s table sequence and create an ordinal number index.

3

=A1.keys@it(EID,HIREDATE)

Set EID as basic key and HIREDATE as time key for A1’s table sequence, and create index on the time key.

4

=A1.keys()

Delete all keys of A1’s table sequence as parameters are absent.

5

=A1.derive(k(EID:3):PID)

Add a serial byte field to the table sequence.

6

=A5.keys@is(PID)

Set PID as the key of A5’s table sequence and create a serial byte index.