Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k0yt7-0002MR-FV for pgsql-novice@arkaria.postgresql.org; Thu, 30 Jul 2020 03:05:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k0yt6-0005od-8n for pgsql-novice@arkaria.postgresql.org; Thu, 30 Jul 2020 03:05:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k0yt6-0005nJ-2M for pgsql-novice@lists.postgresql.org; Thu, 30 Jul 2020 03:05:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k0yt3-0006X7-VK for pgsql-novice@lists.postgresql.org; Thu, 30 Jul 2020 03:05:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 06U35dN21352567; Wed, 29 Jul 2020 23:05:39 -0400 From: Tom Lane To: Chamath Sajeewa cc: pgsql-novice@lists.postgresql.org Subject: Re: PGSQL returning into in insert statement In-reply-to: References: Comments: In-reply-to Chamath Sajeewa message dated "Thu, 30 Jul 2020 08:16:00 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1352565.1596078339.1@sss.pgh.pa.us> Date: Wed, 29 Jul 2020 23:05:39 -0400 Message-ID: <1352566.1596078339@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Chamath Sajeewa writes: > I want to use "returning into" in insert statement. I tried below, > insert into test_table(key,value) values('key1',5) returning value into > returnvalue; > and below error occurred- syntax error at or near "into". That is perfectly legit syntax within a plpgsql function, but it would produce the mentioned syntax error if you tried to use it directly at the SQL level. So I conclude that you're fuzzy about the difference between SQL and plpgsql. You can use plpgsql statements within plpgsql-language function definitions, and within DO blocks. But not as plain SQL. (Plain SQL has no concept of variables either, so "into returnvalue" makes no sense there anyway.) regards, tom lane