[Python] insert, update data into rds DB using sqlalchemy

jua·2021년 12월 6일
0

SQL-python

목록 보기
3/3
from sqlalchemy import create_engine, Table, MetaData

url = "{AWS rds db url: postgresql://{user}:{password}@{rds endpoint}:{port}/{DB name}}"

engine = create_engine(url)
connect = engine.connect()
meta = MetaData()

table = Table(name='{table_name}', 
              metadata=meta, 
              autoload_with=connect, 
              postgresql_ignore_search_path=True)
              
result = table.insert().returning(table.c.{column_name}).values(
        column1 = value1,
        column2 = value2, 
        ...
        )
engine.execute(result)
profile
AI/ML engineer

0개의 댓글