Can LOAD TABLE be used without a column-list?

无人久伴 提交于 2019-12-04 05:52:56

问题


I'm used to unloading and loading data using Sybase ASE using the bcp command-line tool. This doesn't require you to specify any column names.

I understand that the equivalent to bcp in Sybase IQ is the LOAD TABLE command, however I cannot get any data to load without specifying the column names.

datafile.txt:
1,2,3,
1,2,3,

CREATE TABLE myTable (
   fa integer null,
   fb integer null,
   fc integer null
)

LOAD TABLE myTable
FROM 'datafile.txt'
QUOTES OFF 
ESCAPES OFF 

The above yields the following error;

The LOAD statement's column count(0) must be between 1 and 0.  Check the LOAD statement's 'load-specification'

I've seen a few examples of the LOAD TABLE command without a column-list, but I cannot get it to work. Is it only possible with binary files? I've also tried using FORMAT BCP without luck.

It seems mad that column names are a MUST.


回答1:


On IQ the LOAD-statement needs a column-list. E.g. from 15.3 documentation:

The LOAD TABLE command must contain at least one column that needs to be loaded from the file specified in the LOAD TABLE command. Otherwise, an error is reported and the load is not performed.




回答2:


I use a perl wrapper for 'load table' in IQ (or bcp for Sybase or sqlldr for Oracle). No column list needed if the file matches the table:

#/usr/local/bin/perl

use DBIx::BulkUtil;

#...

my ($dbh,$dbu) = DBIx::BulkUtil->iq_connect(
  Server   => $server,
  Database => $db,
  User     => $user,
  Password => $pw,
);

$dbu->bcp_in('mytable', 'datafile.txt', {
  Delimiter => ",",
});


来源:https://stackoverflow.com/questions/31785381/can-load-table-be-used-without-a-column-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!