can a linux program, running on the client side, generate data to load a temp table ?

Started by dfgpostgres5 months ago6 messagesgeneral
Jump to latest
#1dfgpostgres
dfgpostgres3@gmail.com

v15.5 on linux

I've read about and tested a way for a query which calls a user function
which returns a temp table that gets its data from an external program.
Example...

CREATE OR REPLACE FUNCTION run_linux_script()
RETURNS TABLE (script_output text)
LANGUAGE plpgsql
AS $$
BEGIN
-- Create a temporary table for this session
CREATE TEMPORARY TABLE IF NOT EXISTS temp_script_results (
output_line text
);

-- Truncate in case it was used previously in the same session
TRUNCATE temp_script_results;

-- Execute the script and insert the output into the table
COPY temp_script_results (output_line)
FROM PROGRAM '/path/to/my/script/linux_script.pl';

-- Return the results to the calling user
RETURN QUERY SELECT output_line FROM temp_script_results;

-- Clean up
DROP TABLE temp_script_results;
END;
$$;

SELECT * FROM run_linux_script();

It runs, sort of, but fails because it can't find the "linux_script.pl"
script because it's looking for it on the server side.

My question is about whether or not I can get something like this to run on
the client side (where the script can be found).

Thanks in Advance :-)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: dfgpostgres (#1)
Re: can a linux program, running on the client side, generate data to load a temp table ?

dfgpostgres <dfgpostgres3@gmail.com> writes:

My question is about whether or not I can get something like this to run on
the client side (where the script can be found).

psql's "\copy ... from program" might help you. That just addresses
the data transfer though, the other logic will need to be implemented
client-side as well.

regards, tom lane

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: dfgpostgres (#1)
Re: can a linux program, running on the client side, generate data to load a temp table ?

On 6/18/26 5:51 PM, dfgpostgres wrote:

v15.5 on linux

My question is about whether or not I can get something like this to run
on the client side (where the script can be found).

pl/plperlu?:

https://www.postgresql.org/docs/current/plperl-trusted.html

Thanks in Advance :-)

--
Adrian Klaver
adrian.klaver@aklaver.com

#4dfgpostgres
dfgpostgres3@gmail.com
In reply to: Adrian Klaver (#3)
Re: can a linux program, running on the client side, generate data to load a temp table ?

psql's "\copy ... from program" might help you.

Ya, I've used \copy for copying data in the past. But if I'm not mistaken,
the "\copy... from program" runs on the server side. If I'm wrong about
that, if there's a client side version of this, I'm all ears ! And FWIW, a
future release that has this would be great !

plperlu might work in this case. I need the "untrusted" version because I
need to dump a bytea blob out to a file, unzip it, query it (it's a SQLite
DB), use the results of the query to load a temp table. So I need to make
system calls that write to disk and run external programs. I work in a
large corp and made the request to get that up on a DB instance.
Thankfully, I already have a superuser role that might be allowed to
execute the plperlu script.

-dave

On Thu, Jun 18, 2026 at 9:11 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

Show quoted text

On 6/18/26 5:51 PM, dfgpostgres wrote:

v15.5 on linux

My question is about whether or not I can get something like this to run
on the client side (where the script can be found).

pl/plperlu?:

https://www.postgresql.org/docs/current/plperl-trusted.html

Thanks in Advance :-)

--
Adrian Klaver
adrian.klaver@aklaver.com

#5Adrian Klaver
adrian.klaver@aklaver.com
In reply to: dfgpostgres (#4)
Re: can a linux program, running on the client side, generate data to load a temp table ?

On 6/19/26 7:38 AM, dfgpostgres wrote:

psql's "\copy ... from program" might help you.

Ya, I've used \copy for copying data in the past.  But if I'm not
mistaken, the "\copy... from program" runs on the server side.  If I'm
wrong about that, if there's a client side version of this, I'm all
ears !  And FWIW, a future release that has this would be great !

It is client side, but is only available in the the psql client:

https://www.postgresql.org/docs/current/app-psql.html

--
Adrian Klaver
adrian.klaver@aklaver.com

#6Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Adrian Klaver (#5)
Re: can a linux program, running on the client side, generate data to load a temp table ?

On 6/19/26 7:48 AM, Adrian Klaver wrote:

On 6/19/26 7:38 AM, dfgpostgres wrote:

 >> psql's "\copy ... from program" might help you.
Ya, I've used \copy for copying data in the past.  But if I'm not
mistaken, the "\copy... from program" runs on the server side.  If I'm
wrong about that, if there's a client side version of this, I'm all
ears !  And FWIW, a future release that has this would be great !

It is client side, but is only available in the the psql client:

https://www.postgresql.org/docs/current/app-psql.html

Forgot to add to previous post:

"Performs a frontend (client) copy. This is an operation that runs an
SQL COPY command, but instead of the server reading or writing the
specified file, psql reads or writes the file and routes the data
between the server and the local file system. This means that file
accessibility and privileges are those of the local user, not the
server, and no SQL superuser privileges are required."

--
Adrian Klaver
adrian.klaver@aklaver.com