title: Insert a dict into a sql table
body: <p>i wanted to insert some data into my sql but having trouble because there is alot of columns so i would have to write alot of parameters after VALUE. I have a table with all attributes from the json file and a player_id which i add myself</p>
  <pre><code>#Gamelogs for players and Teams
  import requests
  import json
  import psycopg2
  
  # Connect to your postgres DB
  conn = psycopg2.connect(&quot;dbname=NBA user=postgres password=********&quot;)
  
  # Open a cursor to perform database operations
  cur = conn.cursor()
  cur.execute('CREATE TABLE player_logs(&quot;player_id&quot; int,&quot;GameId&quot; int,&quot;Date&quot; int,&quot;Team&quot; VARCHAR(10),&quot;Opponent&quot; VARCHAR(10),&quot;Minutes&quot; int,&quot;Arc3Assists&quot; int,&quot;Arc3FGA&quot; int,&quot;Arc3Frequency&quot; int,&quot;AssistPoints&quot; int,&quot;Assists&quot; int,&quot;AtRimAssists&quot; int,&quot;AtRimFG3AFrequency&quot; int,&quot;Avg2ptShotDistance&quot; int,&quot;Avg3ptShotDistance&quot; int,&quot;BadPassOutOfBoundsTurnovers&quot; int,&quot;BadPassSteals&quot; int,&quot;BadPassTurnovers&quot; int,&quot;Corner3FGA&quot; int,&quot;Corner3Frequency&quot; int,&quot;DeadBallTurnovers&quot; int,&quot;DefArc3ReboundPct&quot; int,&quot;DefFGReboundPct&quot; int,&quot;DefPoss&quot; int,&quot;DefRebounds&quot; int,&quot;DefThreePtReboundPct&quot; int,&quot;DefThreePtRebounds&quot; int,&quot;EfgPct&quot; int,&quot;FG2A&quot; int,&quot;FG2M&quot; int,&quot;FG3A&quot; int,&quot;FG3APct&quot; int,&quot;FTA&quot; int,&quot;Fg2Pct&quot; int,&quot;FirstChancePoints&quot; int,&quot;Fouls&quot; int,&quot;FoulsDrawn&quot; int,&quot;FtPoints&quot; int,&quot;LiveBallTurnoverPct&quot; int,&quot;LiveBallTurnovers&quot; int,&quot;LongMidRangeAccuracy&quot; int,&quot;LongMidRangeAssists&quot; int,&quot;LongMidRangeFGA&quot; int,&quot;LongMidRangeFGM&quot; int,&quot;LongMidRangeFrequency&quot; int,&quot;Loose Ball Fouls&quot; int,&quot;LostBallTurnovers&quot; int,&quot;NonHeaveArc3FGA&quot; int,&quot;OffFGReboundPct&quot; int,&quot;OffPoss&quot; int,&quot;OffRebounds&quot; int,&quot;OffShortMidRangeReboundPct&quot; int,&quot;OffTwoPtReboundPct&quot; int,&quot;OffTwoPtRebounds&quot; int,&quot;OnDefRtg&quot; int,&quot;OnOffRtg&quot; int,&quot;PenaltyArc3FGA&quot; int,&quot;PenaltyArc3Frequency&quot; int,&quot;PenaltyDefPoss&quot; int,&quot;PenaltyEfgPct&quot; int,&quot;PenaltyFG2A&quot; int,&quot;PenaltyFG2M&quot; int,&quot;PenaltyFG3A&quot; int,&quot;PenaltyFg2Pct&quot; int,&quot;PenaltyOffPoss&quot; int,&quot;PenaltyOffPossExcludingTakeFouls&quot; int,&quot;PenaltyOffPossPct&quot; int,&quot;PenaltyPoints&quot; int,&quot;PenaltyPointsExcludingTakeFouls&quot; int,&quot;PenaltyPointsPct&quot; int,&quot;PenaltyShotQualityAvg&quot; int,&quot;PenaltyTsPct&quot; int,&quot;PenaltyTurnovers&quot; int,&quot;Period2Fouls2Minutes&quot; int,&quot;Period3Fouls3Minutes&quot; int,&quot;PlusMinus&quot; int,&quot;Points&quot; int,&quot;PtsUnassisted2s&quot; int,&quot;Rebounds&quot; int,&quot;SecondChanceOffPoss&quot; int,&quot;SelfOReb&quot; int,&quot;SelfORebPct&quot; int,&quot;ShootingFouls&quot; int,&quot;ShootingFoulsDrawnPct&quot; int,&quot;ShortMidRangeAccuracy&quot; int,&quot;ShortMidRangeAssists&quot; int,&quot;ShortMidRangeFGA&quot; int,&quot;ShortMidRangeFGM&quot; int,&quot;ShortMidRangeFrequency&quot; int,&quot;ShortMidRangeOffReboundedPct&quot; int,&quot;ShotQualityAvg&quot; int,&quot;Steals&quot; int,&quot;ThreePtAssists&quot; int,&quot;TotalPoss&quot; int,&quot;TsPct&quot; int,&quot;Turnovers&quot; int,&quot;TwoPtAssists&quot; int,&quot;TwoPtShootingFoulsDrawn&quot; int,&quot;TwoPtShootingFoulsDrawnPct&quot; int,&quot;UnblockedLongMidRangeAccuracy&quot; int,&quot;UnblockedShortMidRangeAccuracy&quot; int,&quot;Usage&quot; int,&quot;Arc3Accuracy&quot; int,&quot;Arc3FGM&quot; int,&quot;Arc3PctAssisted&quot; int,&quot;Assisted2sPct&quot; int,&quot;Assisted3sPct&quot; int,&quot;AtRimAccuracy&quot; int,&quot;AtRimFGA&quot; int,&quot;AtRimFGM&quot; int,&quot;AtRimFrequency&quot; int,&quot;AtRimOffReboundedPct&quot; int,&quot;AtRimPctBlocked&quot; int,&quot;Blocked2s&quot; int,&quot;BlockedShortMidRange&quot; int,&quot;Blocks&quot; int,&quot;BlocksRecoveredPct&quot; int,&quot;Corner3Assists&quot; int,&quot;DefAtRimReboundPct&quot; int,&quot;DefLongMidRangeReboundPct&quot; int,&quot;DefShortMidRangeReboundPct&quot; int,&quot;DefTwoPtReboundPct&quot; int,&quot;DefTwoPtRebounds&quot; int,&quot;FG2APctBlocked&quot; int,&quot;FG3M&quot; int,&quot;Fg2aBlocked&quot; int,&quot;Fg3Pct&quot; int,&quot;LongMidRangeOffReboundedPct&quot; int,&quot;LostBallSteals&quot; int,&quot;NonHeaveArc3Accuracy&quot; int,&quot;NonHeaveArc3FGM&quot; int,&quot;NonHeaveFg3Pct&quot; int,&quot;NonPutbacksAssisted2sPct&quot; int,&quot;NonShootingFoulsDrawn&quot; int,&quot;NonShootingPenaltyNonTakeFoulsDrawn&quot; int,&quot;OffLongMidRangeReboundPct&quot; int,&quot;Offensive Fouls Drawn&quot; int,&quot;PenaltyArc3Accuracy&quot; int,&quot;PenaltyArc3FGM&quot; int,&quot;PenaltyAtRimAccuracy&quot; int,&quot;PenaltyAtRimFGA&quot; int,&quot;PenaltyAtRimFGM&quot; int,&quot;PenaltyAtRimFrequency&quot; int,&quot;PenaltyFG3M&quot; int,&quot;PenaltyFg3Pct&quot; int,&quot;PenaltyFtPoints&quot; int,&quot;PtsAssisted2s&quot; int,&quot;PtsAssisted3s&quot; int,&quot;PtsPutbacks&quot; int,&quot;PtsUnassisted3s&quot; int,&quot;RecoveredBlocks&quot; int,&quot;SecondChanceArc3FGA&quot; int,&quot;SecondChanceArc3Frequency&quot; int,&quot;SecondChanceEfgPct&quot; int,&quot;SecondChanceFG2A&quot; int,&quot;SecondChanceFG2M&quot; int,&quot;SecondChanceFG3A&quot; int,&quot;SecondChanceFg2Pct&quot; int,&quot;SecondChancePoints&quot; int,&quot;SecondChancePointsPct&quot; int,&quot;SecondChanceShotQualityAvg&quot; int,&quot;SecondChanceTsPct&quot; int,&quot;ShortMidRangePctAssisted&quot; int,&quot;ShortMidRangePctBlocked&quot; int,&quot;ThreePtShootingFoulsDrawn&quot; int,&quot;ThreePtShootingFoulsDrawnPct&quot; int,&quot;UnblockedArc3Accuracy&quot; int,&quot;UnblockedAtRimAccuracy&quot; int,&quot;OffArc3ReboundPct&quot; int,&quot;OffThreePtReboundPct&quot; int,&quot;OffThreePtRebounds&quot; int,&quot;Offensive Fouls&quot; int,&quot;Corner3Accuracy&quot; int,&quot;Corner3FGM&quot; int,&quot;ThreePtOffReboundedPct&quot; int,&quot;UnblockedCorner3Accuracy&quot; int,&quot;DefFTReboundPct&quot; int,&quot;FTDefRebounds&quot; int,&quot;Technical Free Throw Trips&quot; int,&quot;BlockedAtRim&quot; int,&quot;LostBallOutOfBoundsTurnovers&quot; int,&quot;OffAtRimReboundPct&quot; int,&quot;BlockedLongMidRange&quot; int,&quot;Charge Fouls Drawn&quot; int,&quot;LongMidRangePctAssisted&quot; int,&quot;NonShootingPenaltyNonTakeFouls&quot; int,&quot;SecondChanceTurnovers&quot; int,&quot;Travels&quot; int,&quot;SecondChanceAtRimFGA&quot; int,&quot;SecondChanceAtRimFrequency&quot; int,&quot;Clear Path Fouls&quot; int,&quot;DefCorner3ReboundPct&quot; int,&quot;HeaveAttempts&quot; int,&quot;LongMidRangePctBlocked&quot; int,&quot;2pt And 1 Free Throw Trips&quot; int,&quot;AtRimPctAssisted&quot; int,&quot;Period3Fouls4Minutes&quot; int,&quot;Period4Fouls4Minutes&quot; int,&quot;Charge Fouls&quot; int,&quot;Loose Ball Fouls Drawn&quot; int,&quot;PeriodOTFouls4Minutes&quot; int,&quot;SecondChanceAtRimAccuracy&quot; int,&quot;SecondChanceAtRimFGM&quot; int,&quot;PenaltyCorner3FGA&quot; int,&quot;PenaltyCorner3Frequency&quot; int,&quot;Corner3PctAssisted&quot; int,&quot;SecondChanceFtPoints&quot; int,&quot;OffCorner3ReboundPct&quot; int,&quot;SecondChanceArc3Accuracy&quot; int,&quot;SecondChanceArc3FGM&quot; int,&quot;SecondChanceFG3M&quot; int,&quot;SecondChanceFg3Pct&quot; int,&quot;3pt And 1 Free Throw Trips&quot; int,&quot;Defensive 3 Seconds Violations&quot; int,&quot;Period4Fouls5Minutes&quot; int,&quot;StepOutOfBoundsTurnovers&quot; int,&quot;Period1Fouls2Minutes&quot;int)')
  x = 'https://api.pbpstats.com/get-all-players-for-league/nba'
  headers = {'user-agent': 'Chrome/88.0.4324.190'}
  jsonData1 = requests.get(x, headers=headers).json() # Player id and name
  
  EntityId = json.loads(json.dumps(jsonData1)[12:-1])
  SeasonType = {'R':'Regular+Season','P':'Playoff+Season','A':'All'}
  EntityType = {'P':'Player','T':'Team'}
  Season = {
              '2008-09',
              '2009-10',
              '2010-11',
              '2011-12',
              '2012-13',
              '2013-14',
              '2014-15',
              '2015-16',
              '2016-17',
              '2017-18',
              '2018-19',
              '2019-20',
              '2020-21'
              }
  def log (S:Season,ST:SeasonType,EI:EntityId,ET:EntityType):
      url = 'https://api.pbpstats.com/get-game-logs/nba'
      payload = {
                  'Season': S,
                  'SeasonType': ST,
                  'EntityId': EI,
                  'EntityType': ET
                  }
      r = requests.get(url, headers=headers, params=payload).json()
      if r == {'error': 'no results'} :
          return()
      else :
          for c in r['multi_row_table_data']:
              j = {'Player_id':EI} 
              c.update(j)
              cur.execute('INSERT INTO player_log (Player_id,GameId,Date,Team,Opponent,Minutes,Arc3Assists,Arc3FGA,Arc3Frequency,AssistPoints,Assists,AtRimAssists,AtRimFG3AFrequency,Avg2ptShotDistance,Avg3ptShotDistance,BadPassOutOfBoundsTurnovers,BadPassSteals,BadPassTurnovers,Corner3FGA,Corner3Frequency,DeadBallTurnovers,DefArc3ReboundPct,DefFGReboundPct,DefPoss,DefRebounds,DefThreePtReboundPct,DefThreePtRebounds,EfgPct,FG2A,FG2M,FG3A,FG3APct,FTA,Fg2Pct,FirstChancePoints,Fouls,FoulsDrawn,FtPoints,LiveBallTurnoverPct,LiveBallTurnovers,LongMidRangeAccuracy,LongMidRangeAssists,LongMidRangeFGA,LongMidRangeFGM,LongMidRangeFrequency,Loose_Ball_Fouls,LostBallTurnovers,NonHeaveArc3FGA,OffFGReboundPct,OffPoss,OffRebounds,OffShortMidRangeReboundPct,OffTwoPtReboundPct,OffTwoPtRebounds,OnDefRtg,OnOffRtg,PenaltyArc3FGA,PenaltyArc3Frequency,PenaltyDefPoss,PenaltyEfgPct,PenaltyFG2A,PenaltyFG2M,PenaltyFG3A,PenaltyFg2Pct,PenaltyOffPoss,PenaltyOffPossExcludingTakeFouls,PenaltyOffPossPct,PenaltyPoints,PenaltyPointsExcludingTakeFouls,PenaltyPointsPct,PenaltyShotQualityAvg,PenaltyTsPct,PenaltyTurnovers,Period2Fouls2Minutes,Period3Fouls3Minutes,PlusMinus,Points,PtsUnassisted2s,Rebounds,SecondChanceOffPoss,SelfOReb,SelfORebPct,ShootingFouls,ShootingFoulsDrawnPct,ShortMidRangeAccuracy,ShortMidRangeAssists,ShortMidRangeFGA,ShortMidRangeFGM,ShortMidRangeFrequency,ShortMidRangeOffReboundedPct,ShotQualityAvg,Steals,ThreePtAssists,TotalPoss,TsPct,Turnovers,TwoPtAssists,TwoPtShootingFoulsDrawn,TwoPtShootingFoulsDrawnPct,UnblockedLongMidRangeAccuracy,UnblockedShortMidRangeAccuracy,Usage,Arc3Accuracy,Arc3FGM,Arc3PctAssisted,Assisted2sPct,Assisted3sPct,AtRimAccuracy,AtRimFGA,AtRimFGM,AtRimFrequency,AtRimOffReboundedPct,AtRimPctBlocked,Blocked2s,BlockedShortMidRange,Blocks,BlocksRecoveredPct,Corner3Assists,DefAtRimReboundPct,DefLongMidRangeReboundPct,DefShortMidRangeReboundPct,DefTwoPtReboundPct,DefTwoPtRebounds,FG2APctBlocked,FG3M,Fg2aBlocked,Fg3Pct,LongMidRangeOffReboundedPct,LostBallSteals,NonHeaveArc3Accuracy,NonHeaveArc3FGM,NonHeaveFg3Pct,NonPutbacksAssisted2sPct,NonShootingFoulsDrawn,NonShootingPenaltyNonTakeFoulsDrawn,OffLongMidRangeReboundPct,Offensive_Fouls_Drawn,PenaltyArc3Accuracy,PenaltyArc3FGM,PenaltyAtRimAccuracy,PenaltyAtRimFGA,PenaltyAtRimFGM,PenaltyAtRimFrequency,PenaltyFG3M,PenaltyFg3Pct,PenaltyFtPoints,PtsAssisted2s,PtsAssisted3s,PtsPutbacks,PtsUnassisted3s,RecoveredBlocks,SecondChanceArc3FGA,SecondChanceArc3Frequency,SecondChanceEfgPct,SecondChanceFG2A,SecondChanceFG2M,SecondChanceFG3A,SecondChanceFg2Pct,SecondChancePoints,SecondChancePointsPct,SecondChanceShotQualityAvg,SecondChanceTsPct,ShortMidRangePctAssisted,ShortMidRangePctBlocked,ThreePtShootingFoulsDrawn,ThreePtShootingFoulsDrawnPct,UnblockedArc3Accuracy,UnblockedAtRimAccuracy,OffArc3ReboundPct,OffThreePtReboundPct,OffThreePtRebounds,Offensive_Fouls,Corner3Accuracy,Corner3FGM,ThreePtOffReboundedPct,UnblockedCorner3Accuracy,DefFTReboundPct,FTDefRebounds,Technical_Free_Throw_Trips,BlockedAtRim,LostBallOutOfBoundsTurnovers,OffAtRimReboundPct,BlockedLongMidRange,Charge_Fouls_Drawn,LongMidRangePctAssisted,NonShootingPenaltyNonTakeFouls,SecondChanceTurnovers,Travels,SecondChanceAtRimFGA,SecondChanceAtRimFrequency,Clear_Path_Fouls,DefCorner3ReboundPct,HeaveAttempts,LongMidRangePctBlocked,&quot;2pt_And_1_Free_Throw_Trips&quot;,AtRimPctAssisted,Period3Fouls4Minutes,Period4Fouls4Minutes,Charge_Fouls,Loose_Ball_Fouls_Drawn,PeriodOTFouls4Minutes,SecondChanceAtRimAccuracy,SecondChanceAtRimFGM,PenaltyCorner3FGA,PenaltyCorner3Frequency,Corner3PctAssisted,SecondChanceFtPoints,OffCorner3ReboundPct,SecondChanceArc3Accuracy,SecondChanceArc3FGM,SecondChanceFG3M,SecondChanceFg3Pct,&quot;3pt_And_1_Free_Throw_Trips&quot;,Defensive_3_Seconds_Violations,Period4Fouls5Minutes,StepOutOfBoundsTurnovers,Period1Fouls2Minutes) VALUES', 
                          c)
      return()    
  
  
  
  y=log('2020-21','Regular+Season','101108','Player')
  
          
  conn.commit()    
  conn.close()
  cur.close()
  </code></pre>
  <p>So was wondering if i could insert the data so it matched with the key and the column name. So the table and dict isnt order the same way either if it makes a difference.</p>