Here’s how to use pselect() function.
Description:
Get the positions of the specified members from a sequence.
Syntax:
A.pselect( x) |
|
A.pselect(x1:y1,x2:y2,......xi:yi) |
The simplified syntax for the composite query using "&&" . It is equal to A.pselect(x1==y1 && x2==y2 &&...... xi==yi). |
Note:
The function gets the position of a member in sequence A and returns the sequence number of a member that fulfils condition x, or returns an empty sequence/null if it cannot find the eligible member. The return value is also subject to the option working with the function.
Options:
@a |
Return a sequence composed of sequence numbers of all the members that fulfill the condition x. When it is not supplied, return the sequence number of the first eligible member. |
@z |
Perform the search backwards from the last member; by default perform the search from the first member. |
@b |
Perform the binary search when A is an ordered sequence by default. Note that in this case xi must be in ascending or descending order. If A is not an ordered sequence, this option could return incorrect result. When it is used with A.pselect(x1:y1,x2:y2,......xi:yi) to find out members that make cmp(x,y) return 0, simply write A.pselect@b(x1:y1,x2:y2,......xi:yi) without including cmp(). |
@s |
It requires that members in A are ordered for expression x. With the binary search, if no members in A can make the expression x return 0, then return the opposite number of the position where x can be inserted. |
@n |
If no sequence member is found, return the result of the length of A plus 1. This option and @a are mutually exclusive |
Parameters:
A |
A sequence |
x |
A boolean expression, whose value can be null. When using @b option, x should be an expression whose return value is an integer |
xi:yi |
xi is an expression, and yi is a comparing value |
Return value:
The sequence numbers of the member that fulfils condition x or that makes the result of expression x equals y in the given sequence. @a option works to return a sequence composed of all the sequence numbers of the member that fulfils condition x, and return a sequence composed of the sequence numbers of all the members when x is null.
Example:
|
A |
|
1 |
[2,5,4,3,2,9,4,9,3] |
|
2 |
=A1.pselect(~>4) |
2 |
3 |
=A1.pselect@a(~>4) |
[2,6,8] |
4 |
=A1.pselect@z(~>4) |
8 |
5 |
=A1.pselect@az(~>4) |
[8,6,2] |
6 |
=[1,3,5,7,9].pselect@b(~-5) |
3. The syntax of A6 and A7 are equal, and their return values are the same. When using a colon, the syntax of using @b doesn’t need to be changed |
7 |
=[1,3,5,7,9].pselect@b(~:5) |
|
8 |
=[1,3,5,7,9].pselect@s(~:4) |
-3. Cannot find 4 and return the opposite number of the position where 4 can be inserted |
9 |
=[1,3,5,7,9].pselect@n(~:4) |
6 |
10 |
=demo.query("select * from EMPLOYEE") |
|
11 |
=A10.pselect(GENDER:"M",DEPT:"Sales") |
6 |
12 |
=demo.query("select * from EMPLOYEE where GENDER='M' order by EID asc") |
EID and GENDER are in the same order |
13 |
=A12.pselect@b(EID:10,GENDER:"M") |
2 |
14 |
=A12.pselect@s(EID:3,GENDER:"M") |
-1. Cannot find the record satisfying EID=3 and GENDER=M and return the opposite number of the position where the record can be inserted |
15 |
=A12.pselect@n(EID:3,GENDER:"M") |
239 |
Note:
If A is not an ordered sequence, and xi is not in ascending or descending order, the use of options @b and @s may bring about incorrect results.