Table Firebird 中的名称有很多额外的 space
Table name in Firebird has a lot of extra space
所以,我在 Firebird 中创建了一个 table,使用 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 时,我得到了这个奇怪的结果:
>>> 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 ']
这到底是怎么回事?这个愚蠢的额外 space 是从哪里来的?为什么我的 table 被命名为 "TEST_TABLE "
而不仅仅是 "TEST_TABLE"
?
字段:
RDB$RELATION_NAME is CHAR(31)
CHAR 用空格填充。
The most important difference is that CHAR is padded with spaces and
VARCHAR 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 contain
value '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
所以,我在 Firebird 中创建了一个 table,使用 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 时,我得到了这个奇怪的结果:
>>> 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 ']
这到底是怎么回事?这个愚蠢的额外 space 是从哪里来的?为什么我的 table 被命名为 "TEST_TABLE "
而不仅仅是 "TEST_TABLE"
?
字段:
RDB$RELATION_NAME is CHAR(31)
CHAR 用空格填充。
The most important difference is that CHAR is padded with spaces and VARCHAR 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 contain value '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