sortx()

Read(190) Label: sortx,

Here’s how to use sortx() function.

ch.sortx()

Description:

Sort records in a channel.

Syntax:

ch.sortx(x,…)

Note:

The function sorts records in channel ch by expression x,… and returns the sorted records as a channel. This is a function for directly getting a result set from the channel.

Parameters:

ch

Channel

x

An expression, according to which the records in a given channel is sorted in acending order

Return value:

Channel

Example:

 

A

 

1

=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE order by EID desc")

Return a cursor with desired records

2

=channel()

Create a channel

3

=A2.sortx(SALARY,EID)

Sort records in the channel by SALARY field and EID field

4

=A1.push(A2)

Push data in A1’s cursor into the channel

5

=A1.fetch()

Fetch data from A1’s cursor

6

=A2.result()

Return result as a cursor

7

=A6.fetch()

cs.sortx()

Description:

Sort data of a cursor.

Syntax:

cs.sortx(x,…;n)

 

Note:

The function sorts cursor cs by expression x, and returns result as a cursor.

Parameters:

cs

A cursor

x

An expression to sort members of cursor cs in ascending order

n

Number of buffer rows; its value will be n times of the default if it is less than 1; by default esProc will uto-compute the value

Options:

   @0  Put records with null values at the end; @0 and @n can’t work together.

@n

It can only be used to make the calculation faster when the value of expression x is a positive integer. In this case, parameter n is treated as a grouping expression over which group of records can be directly numbered. For each group, records will be sorted in the memory. @0 and @n can’t work together.

Return value:

  A cursor

Example:

 

A

 

1

=demo.cursor("select NAME,BIRTHDAY,HIREDATE from Employee")

Return retrieved data as a cursor

2

=A1.sortx(BIRTHDAY)

Sort the cursor’s BIRTHDAY field

3

=A2.fetch()

Retrieve data from cursor A2

4

=demo.cursor("select * from DEPT")

Return retrieved data as a cursor

5

=A4.sortx@0(FATHER).fetch()

Sort records in the cursor by FATHER field and put the one with null value at the end

 Related functions:

cs.fetch()

db.cursor()

 

cs.sortx()

Description:

Sort a cluster cursor.

Syntax:

cs.sortx(x,…;n)

 

Note:

The function sorts cluster cursor cs by expression x and returns a clustrer cursor.

Options:

@c

Won’t merge result sets returned by the nodes but return a cluster cursor segmented in the same way

Parameters:

cs

A cluster cursor

x

An expression by which records in a specified cluster cursor are sorted in ascending order

 

n

Number of buffer rows

Return value:

A cluster cursor

Example:

 

A

 

1

[192.168.0.110:8281,192.168.18.143:8281]

 

2

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

emp.ctx is a distributed composite table file

3

=A2.create()

Open a cluster composite table file

4

=A3.cursor()

Return a cluster cursor

5

=A4.sortx(EID)

Sort A4’s cluster cursor by EID and return result also as a cluster cursor