gpt4 book ai didi

sql - Firebird 中的表名有很多额外的空间

转载 作者:行者123 更新时间:2023-12-04 18:33:00 25 4
gpt4 key购买 nike

所以,我在 Firebird 中创建了一个表,使用 Python fdb 库,如下所示:

>>> import fdb

>>> conn = fdb.connect(...)
>>> sql = "CREATE TABLE test_table(id integer not null)"
>>> cursor = conn.cursor()
>>> cursor.execute(sql)
>>> conn.commit()

但是,当我列出表格时,我得到了这个奇怪的结果:
>>> tables = []
>>> sql = "select rdb$relation_name from rdb$relations
where rdb$view_blr is null and (rdb$system_flag is null or rdb$system_flag = 0)"
>>> cursor.execute(sql)
>>> res = cursor.fetchall()
for r in res:
tables.append(r[0])
>>> tables
['TEST_TABLE ']

到底他妈发生了什么?这个愚蠢的额外空间从何而来?为什么我的表被命名为 "TEST_TABLE "而不仅仅是 "TEST_TABLE" ?

最佳答案

field :

RDB$RELATION_NAME is CHAR(31)
CHAR 用空格填充。

The most important difference is that CHAR is padded with spaces andVARCHAR is not. For example, if you have:

CREATE TABLE t1 ( c1 VARCHAR(2), c2 CHAR(2) );

INSERT INTO t1 (c1,c2) VALUES ('a', 'a');

The column c1 will contain value 'a', while column c2 will containvalue 'a ' with additional space.Trailing spaces are ignored when doing comparisons, so both columns would >match the

WHERE c = 'a'

clause of some query. Trailing spaces are respected by LIKE operator, which >is a source of confusion for beginners


见: http://www.firebirdfaq.org/faq237/

关于sql - Firebird 中的表名有很多额外的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37273469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com