Firebird中的表名有很多额外的空间 [英] Table name in Firebird has a lot of extra space

查看:50
本文介绍了Firebird中的表名有很多额外的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So, I created a table in Firebird, using Python fdb library like so:

>>> import fdb

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

但是,当我列出表时,却得到了这个奇怪的结果:

However, when I list tables, I get this strange result:

>>> 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" ?

What the heck is going on? Where does this stupid extra space come from? Why my table is named "TEST_TABLE " and not just "TEST_TABLE"?

推荐答案

字段:

RDB$RELATION_NAME is CHAR(31)

CHAR用空格填充.

CHAR is padded with spaces.

最重要的区别是CHAR用空格和VARCHAR不是.例如,如果您有:

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

创建表t1(c1 VARCHAR(2),c2 CHAR(2));

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

插入t1(c1,c2)值('a','a');

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

列c1将包含值'a',而列c2将包含值值'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

其中c ='a'

一些查询的子句.LIKE运算符尊重尾随空格,这对于初学者来说是一个困惑的来源

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

请参阅: http://www.firebirdfaq.org/faq237/

这篇关于Firebird中的表名有很多额外的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆