Simon C
Simon C

Reputation: 445

AQL - How to show PK in a SELECT

How do I include the PK when doing a AQL select?

Example:

SELECT * from test.users

Returns:

FirstName, LastName etc

What I really want to know is the PK or key so I can delete a row. How can I include the PK in a SELECT AQL statement.

Upvotes: 4

Views: 6947

Answers (3)

Anand Prakash
Anand Prakash

Reputation: 119

To DELETE the data from the sets - To delete a record from the set, you could use scanAll API which iterates through all the records and delete. During scanCallback call it gets the digest key for each record and deletes. Here is the reference link

http://www.aerospike.com/community/labs/deleting_sets_and_data.html

Once we have extended functionality of retrieving primary index through AQL then you can retrieve primary index key which you have created but make sure you have stored key by calling sendKey attribute of WritePolicy class. SendKey sends user defined key in addition to hash digest on a record put. By default it's not sent.

Upvotes: 2

Damith Ganegoda
Damith Ganegoda

Reputation: 4328

Alternative solution

create extra bin to save primary key and index it. Then you can retrieve this primary key using AQL statement.

Upvotes: 1

sunil
sunil

Reputation: 3567

By default, Aerospike does not store the actual primary key in the database. It stores the 20-byte digest (hash of the key) by default. This will be a huge saving for the large keys. However, in the latest version, this can be changed by the put() operation to store the key also. But the AQL client is not enhanced yet to exploit this fact. I will file an internal ticket for this enhancement.

In the mean time...

  1. option-1 : you can take a backup of your data which will also dump the digests (hash of key) in base64 encoding format. You can use those digests to delete the records.
  2. option-2 : if you write scan code using C/Java or any API, you will get the list of digests too. You can use them to delete the records.

Upvotes: 7

Related Questions