pfind()

Here’s how to use pfind() function.

A.pfind()

Description:

Get the sequence number of a record by its primary key.

Syntax:

A.pfind(k)

Note:

The function gets the sequence number of a record whose primary key value is k. Report error if the key isn’t set; return 0 if the eligible record can’t be found.

Parameters:

A

Record sequence/table sequence

k

Primary key; multiple field values from a composite primary key will be presented in sequence [k1,k2,…] or (k1,k2,…).

Options:

@b

Enable the binary search which requires that A must be ordered by the key, otherwise the result will be wrong.

@s

Return the opposite number of an insertable position number when the eligible record cannot be found

Return value:

The sequence number of the eligible record

Example:

 

A

 

1

=demo.query("select * from EMPLOYEE")

2

=A1. keys (NAME,DEPT)

 

3

=A1.pfind(["Alexis","Sales"])

7; use a sequence to represent the value of a multi-field primay key

4

=demo.query("select * from EMPLOYEE")

This table sequence is ordered by the EID field

 

5

=A4.keys(EID)

 

6

=A4.pfind@b(3)

3; @b is used to enable the binary search in order to speed up the computation

7

=demo.query("select * from EMPLOYEE where GENDER='M'")

8

=A7.keys(EID)

 

9

=A7.pfind@s(7)

-2; Return the opposite number of an insertable position number when the record in which EID=7 cannot be found

Related functions:

A.find()