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 1fuy3W-0003ht-QK for pgsql-general@arkaria.postgresql.org; Wed, 29 Aug 2018 10:50:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fuy3T-0007Hk-9H for pgsql-general@arkaria.postgresql.org; Wed, 29 Aug 2018 10:50:31 +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.89) (envelope-from ) id 1fuy3S-0007HO-UF for pgsql-general@lists.postgresql.org; Wed, 29 Aug 2018 10:50:31 +0000 Received: from 9v6.net-wizard.org ([2a01:4f8:172:2a5c::9] helo=gandalf.net-wizard.org) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fuy3O-0001aO-1M for pgsql-general@postgresql.org; Wed, 29 Aug 2018 10:50:28 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id 8532B80DB5; Wed, 29 Aug 2018 12:50:20 +0200 (CEST) X-Virus-Scanned: Gentoo amavisd-new at aragorn Received: from aragorn.net-wizard.org ([127.0.0.1]) by localhost (aragorn.net-wizard.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nZsXEOCqSdua; Wed, 29 Aug 2018 12:50:15 +0200 (CEST) Received: from MTEC0211 (mtec-lee-dock-2-133.ethz.ch [129.132.6.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: clavadetscher@swisspug.org) by gandalf.net-wizard.org (Postfix) with ESMTPSA id 6EAD980D5E; Wed, 29 Aug 2018 12:50:11 +0200 (CEST) From: "Charles Clavadetscher" To: "'TalGloz'" , References: <1535533938898-0.post@n3.nabble.com> In-Reply-To: <1535533938898-0.post@n3.nabble.com> Subject: RE: Executing a Function with an INSERT INTO command fails Date: Wed, 29 Aug 2018 12:50:04 +0200 Message-ID: <019001d43f86$11742960$345c7c20$@swisspug.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQJVxWXjLOJe92ub2y92injx2xA7XKPTf9PQ Content-Language: de-ch List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi > -----Original Message----- > From: TalGloz [mailto:glozmantal@gmail.com] > Sent: Mittwoch, 29. August 2018 11:12 > To: pgsql-general@postgresql.org > Subject: Executing a Function with an INSERT INTO command fails > > Hello, > > I have this function that executes a C extention function in it and returns a SETOF TEXT > > CREATE OR REPLACE FUNCTION seal_diff_benchmark_pgsql(sealparams > CHARACTER VARYING) RETURNS SETOF TEXT AS $outputVar$ > DECLARE > tempVar1 CHARACTER VARYING; > tempVar2 CHARACTER VARYING; > outputVar text; > sealArray TEXT[]; > outputArray TEXT[]; > BEGIN > FOR i IN 1..2 LOOP > SELECT "Pickup_longitude", "Dropoff_longitude" INTO tempVar1, tempVar2 FROM public.nyc2015_09_enc > WHERE id=i; > sealArray := (SELECT public.seal_diff_benchmark(tempVar1, tempVar2, sealparams)); > outputArray[i] := sealArray[1]; > > INSERT INTO public.runtime_benchmark (test_number, column_names, execution_time, operation_type, > seal_or_sql) VALUES (1, 'Pickup_longitude, Dropoff_longitude', sealArray[2], 'sub', 'seal'); > > END LOOP; > > FOREACH outputVar IN ARRAY outputArray LOOP > RETURN NEXT outputVar; > END LOOP; > END; > $outputVar$ LANGUAGE plpgsql; > > Inside the first FOR LOOP... I've an INSERT INTO... command but nothing gets inserted into the > public.runtime_benchmark table. Executing the INSERT INTO command separately works without any problems so why > doesn't it work inside my PostgreSQL function? > > The user executing the function above with the INSERT command is alsow the owner of the public.runtime_benchmark > table. Do I have to create a trigger function for the public.runtime_benchmark table to be able to insert into > it using some other function? Or is there a simpler way to modify the function above to achieve my goal? No. It is possible to use a normal function. Do you get any error? Does the select deliver any result at all? If yes, is there maybe already a trigger on table public.runtime_benchmark? If not, is there maybe a policy on either public.nyc2015_09_enc or public.runtime_benchmark? If not, could you provide more information on the table? Regards Charles > Best regards, > Tal > > > > -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html