I am using the following two queries (in PostgreSQL/Python):
query_update = """UPDATE my_table
SET {}='{}'
WHERE index={}""".format(*[str(updated_columns), str(updated_values), str(updated_row_indices)])
query_insert = """INSERT INTO my_table ({})
VALUES ('{}')""".format(*[str(updated_columns), str(updated_values), str(updated_row_indices)])
Instead of these two queries, I want to have only one query that will automatically insert record if it doesn't exits. I have two questions:
- How to make these two queries into one query using PostgreSQL? (important)
- How to do the same using MySQL? (optional)