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 1lwQ7H-0003ad-TL for pgsql-general@arkaria.postgresql.org; Thu, 24 Jun 2021 14:14:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lwQ7E-0002tI-Ib for pgsql-general@arkaria.postgresql.org; Thu, 24 Jun 2021 14:14:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lwQ7E-0002t2-6S for pgsql-general@lists.postgresql.org; Thu, 24 Jun 2021 14:14:00 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lwQ7B-0001r4-Jf for pgsql-general@lists.postgresql.org; Thu, 24 Jun 2021 14:13:59 +0000 Received: by mail-ej1-x631.google.com with SMTP id hz1so9815405ejc.1 for ; Thu, 24 Jun 2021 07:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=H/UXKhV2TyPEnZWUO+jg8zlCDzukQFOrHT3JKKRVIpM=; b=ly9xw3A1Cu5nYCPeYatps4PdPDlw6xjo9DDC+y+NIYxPyZCirWCMdvhBcEriDzW+oG L4t9Wi/SbZijIOz51qCKHR1NxvribwfIUqFsKU6UqHViWp6d1WAxfyWv1aLzPiMUh5ai ReFLx4R1wz4rRx0fxMzOG9/UK/U6ukiG3RFgcClHd3WXMxcVq+mhGA5Vx4JtQuf3zrfM ZXBpjP9RvjEKCRo4b2UL+xsjI2siL38gyBHOA8aa/87Fuii+p6plhgVNJwaiKXcCW4jY CDJ+VYm1WQ7b4vwqW8BMJ/HePlcsW2hkCCTiAWnwJcl8ZU9GyRQDwYWZzMk3CoxDTH6n +5aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=H/UXKhV2TyPEnZWUO+jg8zlCDzukQFOrHT3JKKRVIpM=; b=bn0ion7pvge5v9A20vv+89U/483ebMV8hTScfK+8ZqVRkPWAMPTJnGVfB+ISVvemml SR7cLQccq108xBPYoC1V25xIR8XHp1X/0AD+iN020ioejTNSY3MY3WmVXrItPsbuZl3N hTvXJXu0kUf57K8POwnWcy0r221wsJs5zZ83DprQJ8iFEsw74xioI0b1hHd56NUAc0CC D9uQ88uKXDrBgZdAwuFAOEkjT6GN7qygTx8hoh+Xgp/Y/zzOaPAtF87dWQwTQ+ueOYhX HPxJX/h8KL04KTqofHWw9Q7zVJDjrFG2eK0pg0hBKmCUF860HfLCv5SDqxAwYpcG0Bau eT5A== X-Gm-Message-State: AOAM530Wr2RZOTkbQUE8EQBQsK+17HFB22vBctE/StRXfYLHfK3j8Q9u ner8DU1D1M1ixO712XIySkUGXQKWNS9s00W/ X-Google-Smtp-Source: ABdhPJzaSjTU7oAK6D1FTKlEYAZAoEalXlfmQEZZaYpdb9HeU5BrSkGE6Cb1ZCY8kZ3wVQcawXo+fw== X-Received: by 2002:a17:907:1c06:: with SMTP id nc6mr5532340ejc.345.1624544035384; Thu, 24 Jun 2021 07:13:55 -0700 (PDT) Received: from localhost.localdomain (217-149-170-197.nat.highway.telekom.at. [217.149.170.197]) by smtp.gmail.com with ESMTPSA id b24sm1274480ejl.61.2021.06.24.07.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:13:55 -0700 (PDT) Message-ID: <8666e4771042ab431c2cdaf90c6883dbe6423797.camel@cybertec.at> Subject: Re: insert ..... returning problem From: Laurenz Albe To: Michael Ivanov , pgsql-general@lists.postgresql.org Date: Thu, 24 Jun 2021 16:13:54 +0200 In-Reply-To: <3d7fba5a-aecd-935d-c7ae-8dbfe8a253f7@isle.spb.ru> References: <55a5f85f533342d6b4ae4f518a8a29f1f261ce45.camel@cybertec.at> <3d7fba5a-aecd-935d-c7ae-8dbfe8a253f7@isle.spb.ru> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2021-06-24 at 16:25 +0300, Michael Ivanov wrote: > > > I'm trying to insert a record returning column value using the following query: > > > > > > INSERT INTO t_load (load_id, load_type) VALUES (:id, :typ) returning load_idx INTO :idx > > > > > > But when I try to prepare the query I'm getting the following error: > > > > > > PREPARE p1515544c00000001 AS insert into t_load (load_id, load_type) values ($1, $2) returning load_idx into $3]: > > > ERROR: syntax error at or near "into" LINE 1: ...ad_id, load_type) values ($1, $2) returning load_idx into $3 > > > ^ > > > Why 'into var' is not accepted here? > > > > Are you talking about ECPG? > > I am using postgres c library, namely I'm calling PQexec() Then you don't need it. You may be mixing up SQL syntax and PL/pgSQL syntax. Just run the statement without the INTO, and it will return a result set, just like a SELECT would. By the way, you cannot have parameters with PQexec(). Use PQexecParams() for that. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com