The use of sequence in Phoenix

Source: Internet
Author: User

Phoenix--hbase's JDBC Driver

The sequence (Sequence) is a SQL feature provided by Phoenix that allows the generation of a monotonically incrementing number, and the sequence automatically generates sequentially incrementing sequence numbers to provide a unique primary key value automatically.

The syntax for building a sequence using the Create SEQUENCE statement is as follows: Create sequence <deq_name>[start with n][increment by N][minvalue N][maxvalue n][ Cycle][cache N]

Syntax structure:

Parameter description: sqe_name: Sequence name increment: An optional clause that represents the increment of the sequence, a positive number that generates an ascending sequence, and a negative value that generates a descending sequence whose default is 1. MinValue: An optional clause that determines the minimum value maxvalue the sequence generates: An optional clause that determines the maximum value of the sequence generation start: An optional clause that specifies the starting position of the sequence, the starting value of the default increment sequence is MinValue, and the starting value of the descending sequence is maxvalue. Cache: An optional clause that determines whether serial numbers are pre-allocated and stored in memory. Cycle: The optional keyword, when the sequence reaches the maximum or the minimum value, you can continue to reset, if the increment series reached MaxValue, it will continue to increment from MinValue, if the descending series reaches MinValue, it will continue to decrement from MaxValue. If this key is omitted, an error will be returned when the other reaches the maximum or the hour continues to increment/subtract. Example: Creating a default sequence with increments of 1
CREATE SEQUENCE my_sequence;

Create a sequence with a minimum value of 1 and a maximum value of 10 and can be reset

CREATE 1  CYCLE;

查询当前序列号

SELECT  Current  for My_sequence;

查询当前序列的下一个序列号

SELECT NEXT  for My_sequence;

(NEXT VALUE FOR返回当前序列的下一个序列号,CURENT VALUE FOR返回当前序列号,注意:首次引用序列时,必须是NEXT VALUE FOR)

使用UPSERT SELECT语句,并为主键生成一个唯一的序列值

VALUES  into my_table (ID, col1, col2)  VALUESNEXTfor'foo ' ' Bar ');

通过CURRENT VALUE FOR查询某表中某序列为该表分配的最后一个序列号

SELECT  Current  for  from My_tale;

The use of sequence in Phoenix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.