Informix: How to get table contents and column names using dbaccess?
Suppose I have:
- Informix database named "my_database"
- a table named "my_table" with columns "col_1", "col_2" and "col_3":
I can extract the contents of a table by creating a my_table.sql script like:
unload to "my_table.txt"
select * from my_table;
and by calling dbaccess from the command line:
dbaccess my_database my_table.sql
This will create a file my_table.txt with content like:
value_a1|value_a2|value_a3
value_b1|value_b2|value_b3
Now, what do I need to do if I want to get the column names in my_table.txt ? How:
col_1|col_2|col_3
value_a1|value_a2|value_a3
value_b1|value_b2|value_b3
a source to share
None of the standard Informix tools put column names at the top of the output the way you want.
SQLCMD (not Microsoft newbie - the original one available from the IIUG Software Archive ) has the ability to do this; use parameter -H
for column headings (and -T
for getting column types).
sqlcmd -U -d my_database -t my_table -HT -o my_table.txt
sqlunload -d my_database -t my_table -HT -o my_table.txt
SQLCMD can also do CSV output if you need it (but - a bug - it does not format the column rows or column rows correctly).
a source to share