If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Other > Ingres : Unloading a simple table in a comma-delimited file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-09-03, 08:35
Zteev Zteev is offline
Registered User
 
Join Date: Feb 2003
Posts: 17
Question Ingres : Unloading a simple table in a comma-delimited file

Hi people,

I would like to know if there is a way to unload an Ingres table in a comma-delimited file without using isql or other management program. I would like to be able to do it in a shell prompt.

Thanks in advance for your help!

Zteev
Reply With Quote
  #2 (permalink)  
Old 10-10-03, 08:08
dbabren dbabren is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 152
You could use copydb, and then change all the tab delimiters (default) to commas using sed. I find the method I have outlined below easier ...

I usually run sql from within the shell script to query iicolumns and then build a copy statement to copy out the file in the format I choose, again running the copy as a sql statement within the shell script.
__________________
Regards
Dbabren
Reply With Quote
  #3 (permalink)  
Old 10-10-03, 08:20
dbabren dbabren is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 152
Because its Friday! This should work in most UNIX envs (may need tweaking though)

table=$1

sql dbname << END > columns.dat

select column_name, column_sequence
from iicolumns
where table_name = '$table'
order by column_sequence ;
commit ;
\p\g
\q

END

cat columns.dat | grep "^|" | grep -v column_name | sed "s/|//g" | awk '{print $1 }' > column1.dat

numlines=`wc -l column1.dat`
count=1
cat /dev/null > script.out

echo "copy $1 (" >> script.out

for line in `cat column1.dat`
do

if [ $count -eq $numlines ]
then echo $line "= c0nl )" >> script.out
else echo $line "= c0comma," >> script.out
fi
count=`expr $count + 1`

done

echo "into '$1.dat' ;" >> script.out
echo "\p\g" >> script.out
echo "\q" >> script.out

Then do a sql dbname < script.out, and you will have the data in a CSV file, call <table-name>.dat
__________________
Regards
Dbabren
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On