From: Adrian Klaver <adrian.klaver@aklaver.com>
To: tango ward <tangoward15@gmail.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: case statement within insert
Date: Fri, 25 May 2018 06:52:27 -0700
Message-ID: <cc49c9e4-2e81-a726-9dd3-025b90fe5f1d@aklaver.com> (raw)
In-Reply-To: <CAA6wQLJ7Ygy66GnB_Akc+GDcm6LbHt3XD9zX92Y7PiBRXZ=12A@mail.gmail.com>
References: <CAA6wQLJ7Ygy66GnB_Akc+GDcm6LbHt3XD9zX92Y7PiBRXZ=12A@mail.gmail.com>
On 05/25/2018 02:04 AM, tango ward wrote:
>
>
> 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%%'
Shouldn't the above be?:
subjcode like '%%PE%%' or subjcode 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?
>
>
>
>
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, tangoward15@gmail.com
Subject: Re: case statement within insert
In-Reply-To: <cc49c9e4-2e81-a726-9dd3-025b90fe5f1d@aklaver.com>
References: <CAA6wQLJ7Ygy66GnB_Akc+GDcm6LbHt3XD9zX92Y7PiBRXZ=12A@mail.gmail.com> <cc49c9e4-2e81-a726-9dd3-025b90fe5f1d@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox