简体   繁体   中英

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 :

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)

Also tried using 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)

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:

where rdb$relation_name=factura

Your unquoted use of factura makes it a column name of rdb$relation_fields , but no such column exists. 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 ):

where rdb$relation_name='factura'

or, given case (in)sensitivity rules of column names:

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.

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. The single quotes and upper case table name are not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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