Skip to content

Commit

Permalink
Refactored SQL query to use LAST_VALUE and not MAX to get max_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivanshShalabh committed Feb 3, 2025
1 parent 9fdd416 commit 3c7689b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion python_api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_trial_inputs(trial_id, inputs, cur, conn):
while True:
try:
# Fetch the latest max ID
cur.execute("SELECT MAX(id) as id FROM trial_inputs")
cur.execute("SELECT LAST_VALUE(id) OVER (ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS id FROM trial_inputs LIMIT 1")
max_id = cur.fetchone()["id"]
max_id = int(max_id) if max_id is not None else 0 # Handle NULL case

Expand Down

0 comments on commit 3c7689b

Please sign in to comment.