Python Teradata自动增量从一个6位数而不是1开始?

时间:2022-01-13 02:01:46

I want to create a table in Teradata that uses auto-increment in the ID column. The code works, but i just dont know why the ID starts like 100001, 100002.. ect despite stating a start with 1 increment by 1.

我想在Teradata中创建一个在ID列中使用自动增量的表。代码工作,但我只是不知道为什么ID开始像100001,100002 ..等尽管说1开始1增量1。

This is my code:

这是我的代码:

cur = connection.cursor()

create table

create_stmt = """CREATE TABLE my_table,
                                NO FALLBACK,
                                NO BEFORE JOURNAL,
                                NO AFTER JOURNAL,
                                CHECKSUM = DEFAULT
                                ( 
                                 id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 NO CYCLE),
                                word VARCHAR(500) CHARACTER SET UNICODE, 
                                country VARCHAR(50) 
                                ) 
                                PRIMARY INDEX (id);"""
cur.execute(create_stmt)

insert into table

insert_stmt = """INSERT INTO my_table (word,country) VALUES(?,?);"""
mydata=("hello","USA")
my_query=cur.execute(insert_stmt,my_data)

select all to test

sel_all_stmt="sel * from my_table"
cur.execute(sel_all_stmt)
result = cur.fetchall()

I ran the insert statement a few times to see what the auto increment look like and this is what i got:

我运行了几次insert语句,看看自动增量是什么样的,这就是我得到的:

[(100001, u'hello', u'USA'), (1, u'hello', u'USA'), (200001, u'hello', u'USA'), (400001, u'hello', u'USA'), (300001, u'hello', u'USA')]

Any idea why the id is so long?

知道为什么id这么久了吗?

1 个解决方案

#1


1  

Sequential processing defeats the purpose of a massive parallel DBMS.

顺序处理违背了大规模并行DBMS的目的。

Teradata's IDENTITY is not a single sequence, it's multiple sequences in parallel (btw, Standard SQL compliant): Each Parsing Engine (PE) and each AMP requests a range of values and assignes them sequentially. So the numbers assigned to rows within a PE/AMP are sequential, but not across PEs/AMPs.

Teradata的IDENTITY不是单个序列,它是并行的多个序列(顺便说一句,标准SQL兼容):每个解析引擎(PE)和每个AMP请求一系列值并按顺序分配它们。因此,分配给PE / AMP中的行的数字是顺序的,但不是跨PE / AMP。

More details can be found in the manuals.

更多细节可以在手册中找到。

#1


1  

Sequential processing defeats the purpose of a massive parallel DBMS.

顺序处理违背了大规模并行DBMS的目的。

Teradata's IDENTITY is not a single sequence, it's multiple sequences in parallel (btw, Standard SQL compliant): Each Parsing Engine (PE) and each AMP requests a range of values and assignes them sequentially. So the numbers assigned to rows within a PE/AMP are sequential, but not across PEs/AMPs.

Teradata的IDENTITY不是单个序列,它是并行的多个序列(顺便说一句,标准SQL兼容):每个解析引擎(PE)和每个AMP请求一系列值并按顺序分配它们。因此,分配给PE / AMP中的行的数字是顺序的,但不是跨PE / AMP。

More details can be found in the manuals.

更多细节可以在手册中找到。