Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Posts
    17

    Question Unanswered: 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

  2. #2
    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

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •