INSERT INTO users (user_id, first_name, last_name, ads) VALUES (100877, 'Alex', 'Ivanov', 'youtube') ON CONFLICT (user_id)
DO UPDATE SET ads = CASE
WHEN (excluded.ads) IN (users.ads) THEN users.ads || '
newads'
END;
media = {
'file': (fileName, io.BytesIO(rsrc.content), 'application/octet-stream')
}
headers = {
'Authorization': f"Bearer {token}",
'Content-Type': 'application/octet-stream',
'Content-Disposition': f'attachment; filename={fileName}'
}
rdst = requests.post(img_dest, headers=headers, files=media)
response = requests.get(source_link)
with open(path_save_photo, "wb") as img_file:
img_file.write(response.content)
media = {
'file': open(path_save_photo, 'rb')
}
headers = {
'Authorization': f"Bearer {token}",
}
requests.post(img_dest, headers=headers, files=media)
DO
$do$
BEGIN
IF NOT EXISTS (SELECT lastanme FROM info WHERE user_id = 123) THEN
INSERT INTO info (user_id, firstname, lastanme, date_pay) VALUES (123, 'Ivan', 'Petrov', '2022-09-01 00:00:00') RETURNING TRUE;
ELSE
IF (SELECT DATE_PART('day', (SELECT date_pay FROM info WHERE user_id = 123)::timestamp - now()::timestamp)) <= 0 THEN
UPDATE info SET date_pay = now() + interval '31 day', firstname = 'Ivan', WHERE user_id = 123 RETURNING TRUE;
ELSE
UPDATE info SET date_pay = info.date_pay + interval '31 day', firstname = 'Ivan', WHERE user_id = 123 RETURNING TRUE;
END IF;
END IF;
END
$do$