Hi Seldom.
Yes, it would be a nice feature. I think the problem is the c0 or char(0)
format specifiers. They are interpreted as char which means pad with spaces
to the length of the field. I use external tools like awk and sed to trim up
the extra spaces. Try this:
declare global temporary table tt as
select trim(c1) + ',' + trim(c2) + ',' + trim(c3) + ',' as col1
from t on commit preserve rows with norecovery
\p\g
copy session.tt(col1=c0nl) into 'b.dat'
\p\g
and then
cut -f1-3 -d, b.dat > c.dat
or
FOR /F "tokens=1,2,3 delims=," %i in (b.dat) do @echo %i,%j,%k>>c.dat
Here's an example that generates a pipe delimited output with extra spaces
removed.
set SQL="%TEMP%\db_spacereport.sql"
Quote:
%SQL% echo select db='%1', t.system_use, t.number_pages, t.num_rows,
t.row_width, t.table_pagesize, t.table_name, t.table_owner, t.table_type,
|
f.file_name, t.storage_structure, t.overflow_pages from iitables t,
iifile_info f
Quote:
%SQL% echo where t.table_name = f.table_name and t.table_owner =
f.owner_name
%SQL% echo order by system_use, t.table_owner, t.table_name
%SQL% echo \g
%SQL% echo \q
sql -s %1 < %SQL% | awk "/|/ {gsub(\" \",\"\",$0);print $0}"
|
del %SQL%
set SQL=
Paul
-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com
[mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of seldom
isnice
Sent: Thursday, 1 September 2011 8:01 AM
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] copy table into file trim squeeze
Hi
I want to export a table to a comma delimited file.
First I thought select a, b, c from t where ...
but this will delimit by '|' and will have fixed width columns.
This is my table
create table t(c char (20), c2 int, c3 varchar(50));
\p\g
insert into t values('asdf', 1, 'asdf ');
insert into t values('asdf', 2, 'asdf aa ');
insert into t values('asdf', 3, 'asdf bb ');
insert into t values('asdf', 4, 'asdf cc ');
insert into t values('asdf', 5, 'asdf dd ');
insert into t values('asdf', 6, 'asdf ee ');
insert into t values('asdf', 7, 'asdf ff ');
insert into t values('asdf', 8, 'asdf gg ');
And I want to see an output file like:
asdf,1,asdf<nl>
asdf,2,asdf aa<nl>
etc
ie all trailing spaces removed.
So next I tried
declare global temporary table tt as select squeeze(c), squeeze(c2),
squeeze(c3)
from t on commit preserve rows with norecovery
\p\g
(Note the use of "squeeze")
copy session.tt(col1=c0comma,
col2=c0comma,
col3=c0nl) into 'b.dat'
\p\g
But I end up with the trailing spaces ie 20 for column c
and 50 for column c3
It seems like a reasonable thing for the copy command to support ?
Thanks.
_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://ext-cando.kettleriverconsulti...fo/info-ingres