简体   繁体   English

从 Firebird 数据库表中获取列名列表时出错

[英]Error while getting list of column names from a Firebird database table

I tried several times to get a list of tables in firebird using python I tried this Get list of column names from a Firebird database table :我尝试了几次使用 python 获取firebird 中的表列表我尝试了这个从 Firebird 数据库表中获取列名列表

select rdb$field_name from rdb$relation_fields where rdb$relation_name=factura;

but didn't work it shows the error ('Error while preparing SQL statement:\\n- SQLCODE: -206\\n- Dynamic SQL Error\\n- SQL error code = -206\\n- Column unknown\\n- FACTURA\\n- At line 1, column 72', -206, 335544569)但没有工作它显示错误('Error while preparing SQL statement:\\n- SQLCODE: -206\\n- Dynamic SQL Error\\n- SQL error code = -206\\n- Column unknown\\n- FACTURA\\n- At line 1, column 72', -206, 335544569)

Also tried using show table factura;还尝试使用show table factura; but the I recibe the error ('Error while preparing SQL statement:\\n- SQLCODE: -104\\n- Dynamic SQL Error\\n- SQL error code = -104\\n- Token unknown - line 1, column 1\\n- show', -104, 335544569)但是我遇到了错误('Error while preparing SQL statement:\\n- SQLCODE: -104\\n- Dynamic SQL Error\\n- SQL error code = -104\\n- Token unknown - line 1, column 1\\n- show', -104, 335544569)

So, I dont know how to get this list of tables.所以,我不知道如何获得这个表格列表。

只有在 factura 是表的名称时才有效

Note: I have included the query into your answer as it makes it easier to answer.注意:我已将查询包含在您的答案中,因为这样更容易回答。

You get the column unknown - FACTURA error because your where-clause is:您得到列未知 - FACTURA错误,因为您的 where 子句是:

where rdb$relation_name=factura

Your unquoted use of factura makes it a column name of rdb$relation_fields , but no such column exists.您对factura未加引号使用使其成为rdb$relation_fields的列名,但不存在这样的列。 This causes the error.这会导致错误。

Instead you want to select rows whose rdb$relation_name column have the (string) value factura , that means you need to enclose it in single quotes (as was also shown in the accepted answer of the question you refer to ):相反,您要选择rdb$relation_name列具有(字符串)值factura ,这意味着您需要将其括在单引号中(如您所引用的问题的已接受答案中所示):

where rdb$relation_name='factura'

or, given case (in)sensitivity rules of column names:或者,给定列名的大小写(in)敏感性规则:

where rdb$relation_name='FACTURA'

The reason show table factura doesn't work, is because that isn't part of the SQL syntax of Firebird, it only exists in the Firebird ISQL tool. show table factura不起作用的原因是因为它不是 Firebird 的 SQL 语法的一部分,它只存在于 Firebird ISQL 工具中。

Also the table name must be uppercase, or no names will be found.此外,表名必须大写,否则将找不到名称。 Try:尝试:

select rdb$field_name
from   rdb$relation_fields
where  rdb$relation_name='FACTURA'
order by rdb$field_position;

The order by is optional. order by是可选的。 The single quotes and upper case table name are not.单引号大写表名不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM