Get a list of column names from a Firebird database table

How do you get a list of column names in a specific table?

t

Firebird table:

  |  name |  id |  phone_number |

Get list:

columnList = ['name', 'id', 'phone_number']

+9
python sql firebird fdb
source share
2 answers

if you want to get a list of column names in a specific table, this is the sql query you need:

 select rdb$field_name from rdb$relation_fields where rdb$relation_name='YOUR-TABLE_NAME'; 

I tried this in firebird 2.5 and it works.

single quotes around YOUR TABLE-TITLE are required btw

+16
source share

Get a list of columns (comma separated, sort by position) for the entire table:

 SELECT RDB$RELATION_NAME AS TABLE_NAME, list(trim(RDB$FIELD_NAME),',') AS COLUMNS FROM RDB$RELATIONS LEFT JOIN (SELECT * FROM RDB$RELATION_FIELDS ORDER BY RDB$FIELD_POSITION) USING (rdb$relation_name) WHERE (RDB$RELATIONS.RDB$SYSTEM_FLAG IS null OR RDB$RELATIONS.RDB$SYSTEM_FLAG = 0) AND RDB$RELATIONS.rdb$view_blr IS null GROUP BY RDB$RELATION_NAME ORDER BY 1 
0
source share

All Articles