Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
meanspec-hwinfo-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MeanSpec (SCE338 2024-2 Group 1)
meanspec-hwinfo-daemon
Commits
5e3bd7d4
Verified
Commit
5e3bd7d4
authored
6 months ago
by
Eunhak Lee
Browse files
Options
Downloads
Patches
Plain Diff
chore: 부품을 새로 추가할 때 ON CONFLICT 동작 정의
parent
8ac006fc
No related branches found
No related tags found
1 merge request
!1
fix: 대몬이 여러 개 작동할 때 part 를 새로 생성하면서 생기는 conflict 해결
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
push_to_db.py
+4
-1
4 additions, 1 deletion
push_to_db.py
with
4 additions
and
1 deletion
push_to_db.py
+
4
−
1
View file @
5e3bd7d4
...
@@ -62,7 +62,10 @@ def create_new_one(_dict, part_type, _cursor):
...
@@ -62,7 +62,10 @@ def create_new_one(_dict, part_type, _cursor):
values
=
[
value
for
_
,
value
in
_obj
]
values
=
[
value
for
_
,
value
in
_obj
]
sql
=
"""
WITH rows AS (INSERT INTO parts (name, type) VALUES (%s, %s) RETURNING id)
sql
=
"""
WITH rows AS (INSERT INTO parts (name, type) VALUES (%s, %s) RETURNING id)
INSERT INTO part_info_{type} (part_id, {columns}) (SELECT rows.id, {value_entries} FROM rows) RETURNING part_id;
"""
.
format
(
type
=
_part_type_enum
,
columns
=
columns
,
value_entries
=
"
,
"
.
join
([
"
%s
"
]
*
len
(
values
)))
INSERT INTO part_info_{type} (part_id, {columns})
(SELECT rows.id, {value_entries} FROM rows)
ON CONFLICT (name) DO UPDATE name = excluded.name
RETURNING part_id;
"""
.
format
(
type
=
_part_type_enum
,
columns
=
columns
,
value_entries
=
"
,
"
.
join
([
"
%s
"
]
*
len
(
values
)))
_cursor
.
execute
(
sql
,
(
name
,
_part_type_enum
,
*
values
))
_cursor
.
execute
(
sql
,
(
name
,
_part_type_enum
,
*
values
))
data
=
_cursor
.
fetchall
()
data
=
_cursor
.
fetchall
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment