diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-03-25 07:15:43 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2021-03-29 18:09:37 +0000 |
| commit | 194473c58f9f76ff5e9e2f1d24d7fdbf3c86fa7d (patch) | |
| tree | 20a1a5de587d65c814d24ef592b83c4621652eff /internal/database | |
| parent | 876c3ba54c04ad2eb6d493e987b804c046d4aea4 (diff) | |
| download | go-x-pkgsite-194473c58f9f76ff5e9e2f1d24d7fdbf3c86fa7d.tar.xz | |
internal/database: improve temp table creation
- Use LIKE to copy a table's scheme, instead of a SELECT.
- Drop the table on commit.
Change-Id: I82f5bb64e99f7983498a7e81bdeba51025a49b2b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/305529
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/database')
| -rw-r--r-- | internal/database/copy.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/internal/database/copy.go b/internal/database/copy.go index 90dcc07d..74c5d00e 100644 --- a/internal/database/copy.go +++ b/internal/database/copy.go @@ -46,7 +46,7 @@ func (db *DB) CopyUpsert(ctx context.Context, table string, columns []string, sr tempTable := fmt.Sprintf("__%s_copy", table) stmt := fmt.Sprintf(` DROP TABLE IF EXISTS %s; - CREATE TEMP TABLE %[1]s AS SELECT * FROM %s LIMIT 0 + CREATE TEMP TABLE %[1]s (LIKE %s) ON COMMIT DROP `, tempTable, table) _, err = conn.Exec(ctx, stmt) if err != nil { |
