case statement within insert

From: tango ward <tangoward15(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: case statement within insert
Date: 2018-05-25 09:04:25
Message-ID: CAA6wQLJ7Ygy66GnB_Akc+GDcm6LbHt3XD9zX92Y7PiBRXZ=12A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I want to insert data from mysql into a table in postgresql. I want to
check when the subjectcode contains PE or NSTP so I can assign True or
False to another column in destination DB.

# Source data:

# Source data: MySQL
curr_msql.execute(''' SELECT code, subjectname
FROM test_subj ''')

# Destination
for row in curr_msql:
curr_psql.execute(''' INSERT INTO subs (
created, modified,
subjcode, subjname,
is_pe_or_nstp)

VALUES (current_timestamp,
current_timestamp,
%s, %s,
CASE
WHEN code like '%%PE%%' or code like '%%NSTP%%'
THEN True
ELSE False
END) ''', (row['code'], row['subjectname']))

I am getting TypeError: not all arguments converted during string
formatting.

Any advice pls?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-05-25 12:29:10 Re: case statement within insert
Previous Message Michael Paquier 2018-05-25 01:15:17 Re: Streaming Replication between PostGreSQL 9.2.2 on Red Hat and PostGreSQL 9.2.24 on Debian