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

From: dfgpostgres <[email-masked]>
Date: Thu, 18 Jun 2026 20:51:36 -0400

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 :-)

---

From: Tom Lane <[email-masked]>
Date: Thu, 18 Jun 2026 20:56:28 -0400

> 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

---

From: Adrian Klaver <[email-masked]>
Date: Thu, 18 Jun 2026 18:11:22 -0700

> 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

-- 
Adrian Klaver
[email-masked]

---

From: dfgpostgres <[email-masked]>
Date: Fri, 19 Jun 2026 10:38:25 -0400

>>  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

---

From: Adrian Klaver <[email-masked]>
Date: Fri, 19 Jun 2026 07:48:19 -0700

On 6/19/26 7:38 AM, dfgpostgres wrote:
> 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

---

From: Adrian Klaver <[email-masked]>
Date: Fri, 19 Jun 2026 07:50:10 -0700

On 6/19/26 7:48 AM, Adrian Klaver wrote:
>>  >> psql's "\copy ... from program" might help you.

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."