1

The escaped date format

load_data = """LOAD DATA LOCAL INFILE %s INTO TABLE table1
   FIELDS TERMINATED BY '|' ESCAPED BY '' (@ADate)
  SET ADate = 
  IF(@ADate = '', NULL, STR_TO_DATE(@ADate,'%%c/%%e/%%Y %%h:%%i:%%s %%p'))"""
cur.execute(load_data, (ed_file,))

keeps triggering on execute line:

mysql.connector.errors.ProgrammingError: Not enough parameters for the SQL statement

Any suggestions how to fix the problem?

create table table1 (ADate datetime);
ed_file could be empty single line.

2 Answers 2

1

Consider using two parameters for file name and string date format:

load_data = """LOAD DATA LOCAL INFILE %s 
               INTO TABLE table1
               FIELDS TERMINATED BY '|' 
               ESCAPED BY '' (@ADate)
               SET ADate = IF(@ADate = '', NULL, STR_TO_DATE(@ADate, %s))
            """

dt_format = '%c/%e/%Y %h:%i:%s %p'

cur.execute(load_data, (ed_file, dt_format))
conn.commit()
Sign up to request clarification or add additional context in comments.

Comments

0

Wow, I have found a workaround. replace %%s with %%S since both equivalent and big S works. %S Seconds (00 to 59) %s Seconds (00 to 59)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.