correct usage of next_value for a sequence

171 views
Skip to first unread message

Matt Zagrabelny

unread,
Apr 20, 2021, 1:52:50 PM4/20/21
to sqlal...@googlegroups.com
Greetings SQLAlchemy,

I'm attempting to use the next_value function to get the (next) value from a sequence:

        cycle_counter = next_value(Sequence('cycle_seq'))
        print(cycle_counter)

However, the print statement yields:

<next sequence value: cycle_seq>

Does anyone know the correct way to get the value of a sequence?

Thanks for any help!

-m

Mike Bayer

unread,
Apr 20, 2021, 2:14:32 PM4/20/21
to noreply-spamdigest via sqlalchemy
you should execute that with a connection:

with engine.connect() as conn:
    conn.scalar(seq.next_value())



Thanks for any help!

-m


--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Matt Zagrabelny

unread,
Apr 20, 2021, 2:37:12 PM4/20/21
to sqlal...@googlegroups.com
On Tue, Apr 20, 2021 at 1:14 PM Mike Bayer <mik...@zzzcomputing.com> wrote:


On Tue, Apr 20, 2021, at 1:52 PM, 'Matt Zagrabelny' via sqlalchemy wrote:
Greetings SQLAlchemy,

I'm attempting to use the next_value function to get the (next) value from a sequence:

        cycle_counter = next_value(Sequence('cycle_seq'))
        print(cycle_counter)

However, the print statement yields:

<next sequence value: cycle_seq>

Does anyone know the correct way to get the value of a sequence?


you should execute that with a connection:

with engine.connect() as conn:
    conn.scalar(seq.next_value())



Thanks for the tip, Mike!

Best,

-m
Reply all
Reply to author
Forward
0 new messages