Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fMDB6-0000FG-CJ for pgsql-general@arkaria.postgresql.org; Fri, 25 May 2018 13:54:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fMDB5-0001PE-7h for pgsql-general@arkaria.postgresql.org; Fri, 25 May 2018 13:54:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fMDB3-0001P4-Mt for pgsql-general@lists.postgresql.org; Fri, 25 May 2018 13:54:43 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fMDAx-0006ET-4D for pgsql-general@lists.postgresql.org; Fri, 25 May 2018 13:54:41 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 7C4D821E5B; Fri, 25 May 2018 09:52:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 25 May 2018 09:52:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=mp4MU61jHwjpqIHDYtsGOMVmJzdFB sjY44PgDcJxSY8=; b=dp/h6hsskuKdR9W74xAoCbQ6mLcVl/SNRgL8Ewa5yFjYU No3hQtEwU1gEXsk3Q9mD9xDVXkiJt4BQ+KliIqFXTLcNyCChZaZ5/QUJk/WZw0qz UJapKtKLwJgVB1AIw0kYz1TnMKuggel3G99w1eGs7idPK7k5kgLmqUoZ9CA+6/mR ASE+2kdT/Ud0IGg78/o/THlw348jHmbZbqPanPnTht8nVTlnESNZDqQGAlZlzmEu 5VTstzZlLSEyHjoMoVoi9bidG0iSqBPZsZXuvT74ne+ja7Pszmq8l8o+UAkn93Hb w3kSfz3VOx5xGx/y0OGL8dkXbvId+Dx6ETdU6jGZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=mp4MU6 1jHwjpqIHDYtsGOMVmJzdFBsjY44PgDcJxSY8=; b=AlDgorZxZYbFt+j5q7TzfY uKrlJNY+hKFPhPUs4BcYFzMWKIVzrtr7Jit9x8Ni08tLbF2SzHwrjIXifKb4ZGGP 33Z0WobCxLlSwi/LHq95EPey5R+5H1sRf8heMRkDX3oMuZhVkwzvOCeGlZnhq1Jr cA7HfosN84BZm0S2+jCJgpRkNY/eLqJf/CjcnL7iDoESxzk3fB6daIBR2mVFzmGW blomJrykYIo/eXioTShIp8/wLm3kGFNAiVX4A+NMVybCPeOe7g7GBq/4SmjbRwq7 S7siDNnLCTF13qDlFhgxZA71lCJrYv8/TpBTf0AbCP4rEpZfV8Ba6On5YITVXvHQ == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id E8C03E4434; Fri, 25 May 2018 09:52:28 -0400 (EDT) Subject: Re: case statement within insert To: tango ward , "pgsql-generallists.postgresql.org" References: From: Adrian Klaver Message-ID: Date: Fri, 25 May 2018 06:52:27 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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