how to import csv file into sybaseASE with less columns than table field by using format file? how to import csv file into sybaseASE with less columns than table field by using format file? unix unix

how to import csv file into sybaseASE with less columns than table field by using format file?


There are a few problems with your format file.

According to Sybase documentation, you should be using SYBCHAR exclusively:

Host file datatype

The host file datatype refers to the storage format of the field in the host data file, not the datatype of the database table column.

The DBMS knows the datatype of its columns; it does not know how the input file is encoded.

Remember that the first element in the lines describing a column (3 onward) indicates the column in the file. Your data file has no column 5-7. I suspect that's the field provoking the error message.

Also afaik 0 is not a valid colid in the target table. If you want to indicate NULL for a particular column, say it starts at the beginning and has no length,

1 SYBCHAR 0 0 "|" 7 active_flag

Finally, there's no need to account for the row-terminator in the format file. You do that on the bcp command line with the -r option. If you're using Windows, IIRC that would become

bcp client..template in temp.csv -F2 -f bcp.fmt -r \r\n -U -P -S

In Linux of course you'd have to quote or escape the backslashes.

Edit: for clarity, here's what I think your file should look like,

10.061 SYBCHAR 0 0 "|" 5 creation_time1 SYBCHAR 0 0 "|" 6 active_flag1 SYBCHAR 0 10 "|" 1 name2 SYBCHAR 0 4 "|" 2 id3 SYBCHAR 0 5 "|" 3 attr14 SYBCHAR 0 5 "" 4 attr2

If that doesn't work, you'll have to find someone who, um, knows the answer. I don't have a system handy to test on.

Nothing prevents any part of the data file from being mapped to many columns. In field 1 of your format file, though, you mention data file columns 5 & 6, but your data file has only 4 columns. I think that's what the error message it telling you.

do you mean all datatype I put in format file should be 'SYBCHAR'

Yes. The format file can describe text or binary files. Your file is text, so all your data (in the file) are SYBCHAR.