Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INFILE not populating default values 1

Status
Not open for further replies.

fryguy5049

Technical User
Apr 20, 2004
24
US
windows 2000/MySql 4.1
I have a table that has a couple varchar fields set to default values. When I run an insert statement the default value fields fill as expected. When I use an INFILE statement to add data to the table the fields set to default values don't fill properly. Any ideas how I can get the default values to populate using infile? Thanks
 
Do you mean you are using a LOAD DATA INFILE statement, and using blank strings for the columns you want to set to default values? That won't work. What you must do is omit those columns from the file, and name the rest in the LOAD DATA statement:
[tt]
LOAD DATA INFILE 'c:/temp/test.txt'
INTO TABLE tblname
(col1,col2)
[/tt]
In this example, columns other than col1 and col2 will be set to their default values.
 
here is the table:
Code:
CREATE TABLE `pymnts` (
  `Front_Filename` varchar(58) default NULL,
  `Account` varchar(17) default NULL,
  `SizeFront` varchar(100) default NULL,
  `TranCode` varchar(8) default NULL,
  `rec_leng` varchar(45) default '00512',
  `rec_type` varchar(45) NOT NULL [highlight]default 'M000',[/highlight]
  `msg_id` varchar(45) NOT NULL default '3',
  `client_id` varchar(45) NOT NULL default '49004',
  `source` varchar(45) NOT NULL default '702',
  `filler` varchar(45) NOT NULL default '3',
 `pymnt_type` varchar(45) NOT NULL default '2'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
The infile command:
Code:
load data local infile '\\\\server\\\\folder1\\\\folder_B\\\\files\\\\proces\\\\2_01_b.csv'

into table pymnts
fields terminated by ',' enclosed  by '"'   escaped by '\z'
lines terminated by '\r\n'
ignore 1 lines
The file 2_01_b.csv only has data for columns `Front_Filename` through `TranCode` the rest of the fields I want to autofill with the default values. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top