4

I am attempting to populate an SQL table through reading text files via bash to hand off to the table. I have it all working except when trying to add a null value to a datetime field.

mysql --host 10.100.10.19 --port 3306 -utest -ptest << EOF
INSERT INTO imaging.imagestatus (StatusDate, FileName, FolderName, Status, User, CaptureDate, Kind, Preview) VALUES ('2013-05-01T15:25:55', 'fileName1', 'folderName1', 'Status1', 'User1', 'NULL', 'kind1', 'preview1');
EOF

I keep getting:

ERROR 1292 (22007) at line 1: Incorrect datetime value: 'NULL' for column 'CaptureDate' at row 1

for the value labeled 'NULL' which is a data type datetime in the table. I have tried the combinations '\N', '\N', 'NULL', 'null' and ' '

I started to use a temporary date: 00-00-00 00:00:00 but I want it to match other null entry formats or just a blank space in the table. Thanks for the help!

ANSWER-- As was implemented

The value in the text file name "NULL" that is pulled in can be swapped with a variable like a=NULL to get a correct NULL value for a datetime input.

1 Answer 1

8

If you're using quotes, then you're saying that you want the date to be the string 'NULL'. Did you try just using NULL?

INSERT INTO imaging.imagestatus (StatusDate, FileName, FolderName, Status, User, CaptureDate, Kind, Preview) 
VALUES ('2013-05-01T15:25:55', 'fileName1', 'folderName1', 'Status1', 'User1', NULL, 'kind1', 'preview1');
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I don't know how I didn't try that. How embarrassing. I just need to have an if statement check if the text value is the string "NULL" and if so, insert a variable a=NULL into. Thanks for the quick response and your time!

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.