-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
INSERT INTO bottle_alias | ||
SELECT DISTINCT bottle_id, name | ||
INSERT INTO bottle_alias (name, bottle_id) | ||
SELECT DISTINCT ON (name) name, bottle_id | ||
FROM store_price | ||
ON CONFLICT (name) DO UPDATE | ||
SET bottle_id = bottle_alias.bottle_id | ||
WHERE bottle_alias.bottle_id IS NULL; | ||
|
||
UPDATE store_price SET bottle_id = (SELECT bottle_id FROM bottle_alias WHERE name = store_price.name) WHERE bottle_id IS NULL; | ||
|
||
INSERT INTO bottle_alias | ||
SELECT DISTINCT bottle_id, name | ||
INSERT INTO bottle_alias (name, bottle_id) | ||
SELECT DISTINCT ON (name) name, bottle_id | ||
FROM review | ||
ON CONFLICT (name) DO UPDATE | ||
SET bottle_id = bottle_alias.bottle_id | ||
WHERE bottle_alias.bottle_id IS NULL; | ||
|
||
UPDATE review SET bottle_id = (SELECT bottle_id FROM bottle_alias WHERE name = review.name) WHERE bottle_id IS NULL; | ||
|
||
|
||
UPDATE bottle_alias | ||
SET bottle_id = ( | ||
SELECT id FROM bottles WHERE full_name = bottle_alias.name | ||
) | ||
WHERE bottle_id IS NULL; |