From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | tango ward <tangoward15(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: case statement within insert |
Date: | 2018-05-25 13:52:27 |
Message-ID: | cc49c9e4-2e81-a726-9dd3-025b90fe5f1d@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2018-05-25 14:05:32 | Re: case statement within insert |
Previous Message | Justin Pryzby | 2018-05-25 13:49:50 | Re: postgres=# VACUUM FULL pg_statistic => ERROR: missing chunk number 0 for toast value .. in pg_toast_2619 |