Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date value is not correct in sql dump file #14

Open
neerajbg opened this issue Aug 6, 2021 · 1 comment
Open

Date value is not correct in sql dump file #14

neerajbg opened this issue Aug 6, 2021 · 1 comment

Comments

@neerajbg
Copy link

neerajbg commented Aug 6, 2021

For some reasons, the sql file is not having correct date time for the date field .

The resulting sql file shows date time as '&{2021-08-05 00:00:00 +0000 UTC %!s(bool=true)}'

Do I need to do any specific setting for this behaviour. When I restore, it sets date time as 0000-00-00.

Kindly suggest what is the fix for this.

Neeraj

@modelD-svg
Copy link

modelD-svg commented May 5, 2023

Hello, I also experienced this issue. Here's how I fixed it:

Disclaimer: not a good implementation, just a quick fix for a private project

Before dump.go, line 481, insert:

case *sql.NullTime:
	if s.Valid {
		if s.Time.Format(time.TimeOnly) == "00:00:00" {
			fmt.Fprintf(&b, "'%s'", s.Time.Format(time.DateOnly))
		} else {
			fmt.Fprintf(&b, "'%s'", s.Time.Format(time.DateTime))
		}
	} else {
		b.WriteString(nullType)
	}

Not sure if this works for all database-types. Tested with mariadb 10.5.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants