cs .fetch()

Read(487) Label: cursor, fetch records,

Description:

Fetch one or more records from a cursor/distributed cursor.

Syntax:

cs.fetch(n;x)

Note:

Using a cursor, the function fetches n records, or fetches records continuously till the value of expression x (Here x doesn’t return a boolean value) changes or becomes true (Here x returns a boolean value), and then returns them as a sequence/record sequence/table sequence or returns null if the cursor has already been fetched out. It is often used to retrieve a large amount of data in batches. When both n and x are omitted, the function returns all records in a cursor and then closes the cursor. Only one of the parameters n and x is valid.

Parameters:

cs

A cursor/distributed cursor

n

An integer

x

Grouping expression, according to which cs is sorted. With x, n will be ignored

Options:

@0

Won’t actually fetched out the selected data from the cursor. The option enables an action functionally equivalent to copying the data; it doesn’t support parameter x.

@x

Close the cursor after data is fetched.

@o

Return a table sequence

Return value:

   A sequence/record sequence/table sequence

Example:

 

A

 

1

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

Return a cursor of retrieved data sorted by SALARY.

2

=A1.fetch@0(3)

Select top 3 highest-paid employees.

3

=A1.derive(interval@y(BIRTHDAY,HIREDATE):EntryAge, age(HIREDATE):WorkAge)

IMG_256

With @0 option used in A2, A3 fetches data from a complete cursor

4

=A1.fetch()

 

5

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

 

6

=A1.fetch(;SALARY)

Stop data retrieval when SALARY change to select a group of highest- and equally-paid employees..

7

=A1.fetch()

Return the remaining records in the cursor.

8

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

 

9

=A5.fetch@x(3)

Close the cursor after data is fetched.

10

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

 

11

=A7.fetch(3;SALARY==13000)

Stop data retrieval when the value of the expression is true

 

 

A

 

1

[192.168.0.110:8281,192.168.18.143:8281]

Nodes

2

=file@0("emp.ctx", A1)

emp.ctx is a distributed file across the nodes; node 192.168.0.110 holds a part where EID is from 1 to 250 and node 192.168.18.143 holds another part where EID is from 251 to 500

3

=A2.create()

Open a distributed composite table

4

=A3.cursor()

Return a distributed cursor

5

=A4.fetch()

Fetch records form the distributed cursor

Related functions:

db.cursor()

cs.skip()