public inbox for [email protected]  
help / color / mirror / Atom feed
From: Roland Müller <[email protected]>
To: [email protected]
Subject: Re: Linux file permission for COPY TO SQL command
Date: Wed, 29 Oct 2025 18:12:59 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>

Hello,


COPY TO  stores the output into a file on the server rather than in your 
local where client is running.


Spaces in the file name are actually no issue:

$ psql -h 172.17.0.2 -U postgres -c "COPY (SELECT * FROM pg_class) TO 
'/var/tmp/pg_class.       OUT  x'"
Password for user postgres:
COPY 420

... but the output file is on the server - in this example inside a 
docker container

postgres@7680e256387f:~$ ls -ltr /var/tmp
total 208
...
-rw-r--r-- 1 postgres postgres 49291 Oct 29 16:08 'pg_class.  OUT  x'


Copying to client side can be done with \copy (<query or table>) to 
'<output file>';


BR/Pozdrawiam,

Roland


On 10/29/25 01:03, Rob Sargent wrote:
>
>
>> On Oct 28, 2025, at 9:39 AM, Krzysztof <[email protected]> wrote:
>>
>> 
>>
>> I try to use COPY TO command to copy results of a SELECT but I get 
>> this message:
>>
>> ERROR:  could not open file "a file" for writing: Permission denied
>>
>
> Is there really a space in the actual file name. That might get 
> tricky. You’re suggesting the file already exists: is that true? 
> Directory permissions?
>>
>> User, group and other are granted full permission to this file. What 
>> should I do more to get this working?
>>
>> -- 
>> Pozdrawiam
>> Krzysztof Jasieński

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Linux file permission for COPY TO SQL command
  In-Reply-To: <[email protected]>

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

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