Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icA77-0001UY-OQ for pgsql-general@arkaria.postgresql.org; Tue, 03 Dec 2019 15:29:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icA76-00022M-Ht for pgsql-general@arkaria.postgresql.org; Tue, 03 Dec 2019 15:29:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icA74-000227-Lb for pgsql-general@lists.postgresql.org; Tue, 03 Dec 2019 15:29:20 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1icA71-0006ga-CA for pgsql-general@postgresql.org; Tue, 03 Dec 2019 15:29:17 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id A3CC8C59; Tue, 3 Dec 2019 10:29:12 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 03 Dec 2019 10:29:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=b gVG827PBhh+UGhHh4SbCfPCOmWlVgrSJBI9P6o5IuQ=; b=3Drw8l6A7XOHMo42o rqF25UYG5rH6+R4d6rdBdOQOUIa675hs/Ue9LLjuF2ePWYC/QCjraU3I8WUQ6zHu nqmwKebXwIt6JoZnBrVSo3b/dl2ML6qfBEt0IEwDudgLV1p5f1nqZ+VA7p96iTcR 2ney24aRjndELQLfATKPGLU0n4gvst8GZLF9SYYdENAl82/hO7ADbyRsuH8wt0VI jo+IDpg9o3oyhUu44u+iiwC+2PQR6Ig8jWqLTtHubexPI1sls1yFEL+cdexOEVAg Ual+0rwzN9sZYXcmdokZBClxtxzIrIKR1B0x+e2M2pjuccGDeHwgkqessc4DUUyC VBjpg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=bgVG827PBhh+UGhHh4SbCfPCOmWlVgrSJBI9P6o5I uQ=; b=vQEi2iXErQkPkERXPOsp5AoO0YsPtbaVahvEjCrib5JWh2kJfy/ERjlWs WlyuXuF2ccpaQFTUL/XOqUhibWyu72IbjVmFM1z6IXqYaUwbjNotDKPIv9GtkXaE Y3J/X4AtvKEGtj8MdQWTePHTSPj3h5kGXB2BBmGI0Brj6yuQoPlzvlLwgMRNgk/m nw2XbyrXIXYw2PK8+DqiqXB57qVrpPOsmPL2kQKlTp7vElH94Vy7CCpGvg1AHWdX mXigPcM8YBMWSHi09qpM4AXEyDvlEtjEpkGpv4jLuChLEkgg/dfDA/K2sYg5yTTC gAw7czuzf2oWZFRROunUOyJvgj0WA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudejjedgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejuddrvddu vddrudegledrkeehnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrg hvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.149.85]) by mail.messagingengine.com (Postfix) with ESMTPA id 09498306010D; Tue, 3 Dec 2019 10:29:10 -0500 (EST) Subject: Re: Syntax error for UPDATE ... RETURNING INTO STRICT To: Alexander Farber , Patrick FICHE Cc: pgsql-general References: From: Adrian Klaver Message-ID: <15a043b0-142d-7730-9ed1-2f2a37b876af@aklaver.com> Date: Tue, 3 Dec 2019 07:29:10 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 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 12/3/19 3:37 AM, Alexander Farber wrote: > Thank you Patrick - > > On Tue, Dec 3, 2019 at 11:49 AM Patrick FICHE > wrote: > > > It seems that STRICT is the issue.____ > > But why does your function return a table of boolean in this case ?____ > > As it only updates one record, it would probably be easier to return > a boolean only.____ > > CREATE OR REPLACE FUNCTION words_toggle_puzzle( >                 in_mid     bigint >         ) RETURNS boolean >  AS > $func$ >         UPDATE words_moves >         SET puzzle = NOT puzzle >         WHERE mid = in_mid >         RETURNING puzzle; > $func$ LANGUAGE sql; > > > your suggestion works well, thank you. > > I wanted to use strict, because the mid is a PK - so there should always > be an exactly one record that has been updated Which you will get without STRICT: https://www.postgresql.org/docs/11/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW "For INSERT/UPDATE/DELETE with RETURNING, PL/pgSQL reports an error for more than one returned row, even when STRICT is not specified. This is because there is no option such as ORDER BY with which to determine which affected row should be returned." Though I still not sure what was wrong with your initial attempt?: ERROR: 42601: syntax error at or near "INTO" LINE 11: INTO STRICT out_puzzle; ^ LOCATION: scanner_yyerror, scan.l:1128 From the error it looks like a hidden space issue or something. > > (or otherwise, in very strange cases - the SQL would fail and my > java-servlet would throw SQLException) > > Regards > Alex > -- Adrian Klaver adrian.klaver@aklaver.com