pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charles Clavadetscher <clavadetscher@swisspug.org>
To: 'TalGloz' <glozmantal@gmail.com>
To: pgsql-general@postgresql.org
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> (raw)
In-Reply-To: <1535533938898-0.post@n3.nabble.com>
References: <1535533938898-0.post@n3.nabble.com>

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






view thread (14+ messages)  latest in thread

Message-ID: <019001d43f86$11742960$345c7c20$@swisspug.org>
Permalink:  ../019001d43f86$11742960$345c7c20$@swisspug.org/
Also on:    postgresql.org/message-id/019001d43f86$11742960$345c7c20$@swisspug.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: clavadetscher@swisspug.org, glozmantal@gmail.com
  Subject: Re: Executing a Function with an INSERT INTO command fails
  In-Reply-To: <019001d43f86$11742960$345c7c20$@swisspug.org>
  References: <1535533938898-0.post@n3.nabble.com> <019001d43f86$11742960$345c7c20$@swisspug.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox