0

Is there solution for '0000-00-00 00:00:00' problem, without changing table?

I have "[]" in this query:

dbh.select_all("select j.n, j.name, j.dsc, j.flag, j.td from job j where j.td='0000-00-00 00:00:00'")

I look solution for this: http://rubyforge.org/tracker/index.php?func=detail&aid=22243&group_id=234&atid=967

2
  • Can you be clearer about the problem you are having? Commented Mar 23, 2009 at 15:33
  • rubyforge.org/tracker/… Commented Mar 23, 2009 at 16:07

3 Answers 3

2

So your default is '0000-00-00 00:00:00' and you can't change it. I dug up my ruby-dbi mailing list archives and found the following explanation:

The problem with the latter case is that it can't be coerced to a DateTime object because it's not a valid time... Honestly, I'm surprised mysql allows it at all. Either way, you'll need to turn type conversion off (see DBI.convert_types=) to get this default value to work or change it and all occurrences of it in your database, or use bind_coltype to treat it as string instead.

See this mailing list archive.

Sign up to request clarification or add additional context in comments.

Comments

0

I usually declare my datetimes as accepting NULL, e.g.:

dtime DATETIME NULL DEFAULT NULL

That way I can check if a field IS NULL rather than if a field = '0000-00-00 00:00:00'.

Comments

0

You can just cast the "0000-00-00 00:00:00" to NULL:

SELECT IF(mytime="0000-00-00 00:00:00",NULL,mytime) FROM mytable;

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.