go-mysql-server icon indicating copy to clipboard operation
go-mysql-server copied to clipboard

Support JOIN in UPDATE for unkeyed tables

Open jnu opened this issue 4 years ago • 4 comments

Hi all, I'm seeing a strange error about converting time in a query that shouldn't be using any time column at all. The error I see is:

unable to cast time.Time{wall:0xd7bb0d0, ext:63763889199, loc:(*time.Location)(nil)} of type time.Time to int64

What's puzzling is the query I'm running ostensibly doesn't have anything to do with time.

A simplified version of where we're hitting the error looks like:

// Create a temporary table. Our real table has more columns than this, but
// none are datetime columns so I don't think they're relevant.
_, err := db.ExecContext(ctx, `
	CREATE TEMPORARY TABLE client_list (
		client_id varchar(255) not null,
		site_id varchar(255) not null,
		site_name varchar(255)
	)`)

// Load some data into the temp table, for example:
_, err = db.ExecContext(ctx, `
	INSERT INTO client_list (client_id, site_id)
	VALUES (?, ?), (?, ?), (?, ?)
	`, "client1", "siteA", "client2", "siteA", "client3", "siteB")


// Now we try to fill out more columns in the temp table using other
// non-temp tables in the database. (Avoiding a join since this info will
// be referenced a few times in the transaction.)
// Our real query does something slightly different, but nothing to do with
// time. But this query somehow still fails with the `time` conversion error.
_, err = db.ExecContext(ctx, `
	UPDATE client_list
	INNER JOIN site ON client_list.site_id = site.d
	SET client_list.site_name= site.name
	`)

The site table does have some time columns, which look like:

  `created` timestamp DEFAULT CURRENT_TIMESTAMP,
  `updated` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted` timestamp NULL,

Is the UPDATE/INNERJOIN query referencing these columns implicitly?

I can look into finding a simpler repro case! And for reference, I don't see this issue running my queries in mysql8.

Thanks for your help, and for your incredibly useful library!

jnu avatar Aug 06 '21 23:08 jnu