You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by Ns G <ns...@gmail.com> on 2015/08/22 16:59:49 UTC
REG: Getting the current value of a sequence
Hi All,
I have a requirement where the sequence number is to be prefetched and then
used in upsert query.
I know that Current Value for a sequence number gives me the last used
value. But It does not return value for the first time until and unless
used in a upsert query.
Is there any alternative to get the sequence immediately after declaration
and before using in a upsert query?
Thanks,
Satya
Re: REG: Getting the current value of a sequence
Posted by Ns G <ns...@gmail.com>.
Thank you James and Ravi. This has helped
Satya
On 22-Aug-2015 11:29 pm, "James Taylor" <ja...@apache.org> wrote:
> Hi Satya,
> You can do a NEXT VALUE FOR in a SELECT clause without a from clause like
> this:
> SELECT NEXT VALUE FOR my_seq;
>
> This will allocate a block of sequences from the server (as determined by
> the CACHE clause when you create the sequence), cache them on the client,
> and dole them out as NEXT VALUE FOR calls are made.
>
> If you need to prefetch a guaranteed contiguous block of sequences, you
> may do this:
> SELECT NEXT 1000 VALUES FOR my_seq;
>
> This call would immediately use all 1000 values, so the next call to NEXT
> VALUE FOR or NEXT VALUES FOR would start from at least 1001.
>
> Thanks,
> James
>
>
>
> On Sat, Aug 22, 2015 at 10:27 AM, Ravi Kiran <ma...@gmail.com>
> wrote:
>
>> Hi Satya,
>>
>> Unless you call NEXT VALUE FOR on a sequence *the first time*, you
>> wouldn't be getting the CURRENT VALUE . So , instead of getting the
>> CURRENT VALUE, you can get the NEXT VALUE and then pass to your upsert
>> query.
>>
>> Hope this helps
>>
>>
>>
>>
>>
>> On Sat, Aug 22, 2015 at 7:59 AM, Ns G <ns...@gmail.com> wrote:
>>
>>> Hi All,
>>>
>>> I have a requirement where the sequence number is to be prefetched and
>>> then used in upsert query.
>>>
>>> I know that Current Value for a sequence number gives me the last used
>>> value. But It does not return value for the first time until and unless
>>> used in a upsert query.
>>>
>>>
>>> Is there any alternative to get the sequence immediately after
>>> declaration and before using in a upsert query?
>>>
>>> Thanks,
>>> Satya
>>>
>>
>>
>
Re: REG: Getting the current value of a sequence
Posted by James Taylor <ja...@apache.org>.
Hi Satya,
You can do a NEXT VALUE FOR in a SELECT clause without a from clause like
this:
SELECT NEXT VALUE FOR my_seq;
This will allocate a block of sequences from the server (as determined by
the CACHE clause when you create the sequence), cache them on the client,
and dole them out as NEXT VALUE FOR calls are made.
If you need to prefetch a guaranteed contiguous block of sequences, you may
do this:
SELECT NEXT 1000 VALUES FOR my_seq;
This call would immediately use all 1000 values, so the next call to NEXT
VALUE FOR or NEXT VALUES FOR would start from at least 1001.
Thanks,
James
On Sat, Aug 22, 2015 at 10:27 AM, Ravi Kiran <ma...@gmail.com>
wrote:
> Hi Satya,
>
> Unless you call NEXT VALUE FOR on a sequence *the first time*, you
> wouldn't be getting the CURRENT VALUE . So , instead of getting the
> CURRENT VALUE, you can get the NEXT VALUE and then pass to your upsert
> query.
>
> Hope this helps
>
>
>
>
>
> On Sat, Aug 22, 2015 at 7:59 AM, Ns G <ns...@gmail.com> wrote:
>
>> Hi All,
>>
>> I have a requirement where the sequence number is to be prefetched and
>> then used in upsert query.
>>
>> I know that Current Value for a sequence number gives me the last used
>> value. But It does not return value for the first time until and unless
>> used in a upsert query.
>>
>>
>> Is there any alternative to get the sequence immediately after
>> declaration and before using in a upsert query?
>>
>> Thanks,
>> Satya
>>
>
>
Re: REG: Getting the current value of a sequence
Posted by Ravi Kiran <ma...@gmail.com>.
Hi Satya,
Unless you call NEXT VALUE FOR on a sequence *the first time*, you
wouldn't be getting the CURRENT VALUE . So , instead of getting the
CURRENT VALUE, you can get the NEXT VALUE and then pass to your upsert
query.
Hope this helps
On Sat, Aug 22, 2015 at 7:59 AM, Ns G <ns...@gmail.com> wrote:
> Hi All,
>
> I have a requirement where the sequence number is to be prefetched and
> then used in upsert query.
>
> I know that Current Value for a sequence number gives me the last used
> value. But It does not return value for the first time until and unless
> used in a upsert query.
>
>
> Is there any alternative to get the sequence immediately after declaration
> and before using in a upsert query?
>
> Thanks,
> Satya
>