Я пытался объединить две таблицы с разных серверов в postgres. Но он продолжает говорить, что у меня синтаксическая ошибка
ProgrammingError: syntax error at or near "IF"
LINE 1: INSERT INTO Property__C VALUES IF NOT EXISTS(1,'a0236000002N...
Пожалуйста, помогите или каким-либо другим способом объединить 2 таблицы с разных серверов?
import psycopg2
heroku_conn = psycopg2.connect("dbname = '@@@@@' user = '@@@@@' password = '@@@@' host = '@@@' port = '@@@'")
heroku_cur = heroku_conn.cursor()
local_conn = psycopg2.connect("dbname = '***' user = '***' password = '***' host = 'localhost' port = '***'")
local_cur = local_conn.cursor()
def create_table_local_postgres():
local_cur.execute("CREATE TABLE IF NOT EXISTS Property__C (ID NUMERIC, SFID TEXT, NAME TEXT, THUMBNAIL__C TEXT, BEDS__C NUMERIC, ADDRESS__C TEXT, BATHS__C NUMERIC, BROKER__C TEXT, DESCRIPTION__C TEXT, STATE TEXT, CITY__C TEXT, ZIP__C NUMERIC, TITLE__C TEXT, PICTURE__C TEXT, PRICE__C REAL, LOCATION__LATITUDE__S NUMERIC, LOCATION__LONGITUDE__S NUMERIC)")
local_conn.commit()
local_conn.close()
def insert_local_postgres():
heroku_cur.execute("SELECT * FROM property__c")
row = heroku_cur.fetchall()
for item in row:
ID = item[0]
SFID = item[1]
NAME = item[2]
THUMBNAIL__C = item[3]
BEDS__C = item[4]
ADDRESS__C = item[5]
BATHS__C = item[6]
BROKER__C = item[7]
DESCRIPTION__C = item[8]
STATE = item[9]
CITY__C = item[10]
ZIP__C = item[11]
TITLE__C = item[12]
PICTURE__C = item[13]
PRICE__C = item[14]
LOCATION__LATITUDE__S = item[15]
LOCATION__LONGITUDE__S = item[16]
local_cur.execute("INSERT INTO Property__C VALUES IF NOT EXISTS(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", (ID, SFID, NAME, THUMBNAIL__C, BEDS__C, ADDRESS__C, BATHS__C, BROKER__C, DESCRIPTION__C, STATE, CITY__C, ZIP__C, TITLE__C, PICTURE__C, PRICE__C, LOCATION__LATITUDE__S, LOCATION__LONGITUDE__S))
print(item)
print('\n')
local_conn.commit()
local_conn.close()