Updates data in tables on databases connected with built-in PostgreSQL and SQL Connection. If the Primary Key does not exist, it will be registered as a new record.
morph_lib.database
# 📦 Package: morph_lib.database
# 🛠️ Function: insert_or_update_records

insert_or_update_records(
	data: pd.DataFrame,
	primary_keys: List[str]
	table_name: str,
	connection: Optional[str]
) -> None
対応データベース
  • PostgreSQL
  • MySQL
  • Snowflake

Parameters

data
pd.DataFrame
required
The actual data to be passed to the function. The columns specified in primary_keys must always be present.
primary_keys
List[str]
required
Specify the column names that will be the Primary Key of the table.
table_name
str
required
Specify the table name.
connection
str
The destination of the connection other than the builtin registered on the screen (optional)
  • If not specified, it will be set to built-in postgresql.

Example

from morph_lib.database import insert_or_update_records

@morph.func
@morph.load_data("user_data")
def func_name(context):
	user_data: pd.DataFrame = context.data["user_data"]
	insert_or_update_records(
		user_data,
		["user_id"]
		"user",
	)