Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a6kFn-00078T-IP for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Dec 2015 19:18:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a6kFn-00038I-50 for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Dec 2015 19:18:19 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a6kFm-000387-M4 for pgsql-bugs@postgresql.org; Wed, 09 Dec 2015 19:18:18 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1a6kFj-0000x5-NE for pgsql-bugs@postgresql.org; Wed, 09 Dec 2015 19:18:17 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id 3788A860004; Wed, 9 Dec 2015 20:18:14 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-5.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (p57B4E835.dip0.t-ipconnect.de [87.180.232.53]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 98DD9860002; Wed, 9 Dec 2015 20:18:10 +0100 (CET) Received: by anarazel.de (Postfix, from userid 1000) id EF69B104760; Wed, 9 Dec 2015 20:18:09 +0100 (CET) Date: Wed, 9 Dec 2015 20:18:09 +0100 From: Andres Freund To: tarunt@chisquare.in Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13808: Upsert not working Message-ID: <20151209191809.GM28762@awork2.anarazel.de> References: <20151209090153.872.86659@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151209090153.872.86659@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.7 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 2015-12-09 09:01:53 +0000, tarunt@chisquare.in wrote: > drop table daily_deposits; > create table daily_deposits > ( id int, > fdd timestamp, > ldd timestamp, > fda double precision, > lda double precision > ); > > drop table user_first_last; > create table user_first_last > ( UserId int, > FirstLoginDate timestamp, > LastLoginDate timestamp, > FirstLoginAmt double precision, > LastLoginAmt double precision > ); > > > INSERT INTO user_first_last AS ufl (UserId, > FirstLoginDate,LastLoginDate,FirstLoginAmt,LastLoginAmt) > select id, fdd, ldd,fda, lda > from daily_deposits > ON CONFLICT (UserId) > DO UPDATE > SET FirstLoginAmt = case when excluded.fdd < ufl.FirstLoginDate then > excluded.fda else ufl.FirstLoginAmt END, > LastLoginAmt = case when excluded.ldd > ufl.LastLoginDate then > excluded.lda else ufl.LastLoginAmt END, > FirstLoginDate = case when excluded.fdd < ufl.FirstLoginDate then > excluded.fdd else ufl.FirstLoginDate END, > LastLoginDate = case when excluded.ldd > ufl.LastLoginDate then > excluded.ldd else ufl.LastLoginDate END; > > ERROR: column excluded.fdd does not exist > LINE 6: SET FirstLoginAmt = case when excluded.fdd < ufl.FirstLogi... > ^ > ********** Error ********** > > ERROR: column excluded.fdd does not exist > SQL state: 42703 > Character: 222 'excluded' is about the relation you're inserting to (i.e. user_first_last / ufl, which doesn't have a fdd column), not about the table you're selecting from. Regards, Andres -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs