Skip to content

Conversation

ggnmstr
Copy link
Contributor

@ggnmstr ggnmstr commented Jun 9, 2025

Vanilla PostgreSQL does not allow COPY statements with relative path as it may lead to overriding database files and result in database corruption. This puts the same restriction on pg_duckdb. It's important to continue to allow COPY to URIs though.

Copy link
Collaborator

@JelteF JelteF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to align here with postgres. It's indeed confusion that can easily lead to bad data corruption, because people often don't know the relative path of their postgres install.

Tests are failing though, so that one needs to be updated. Also, would be good to add a test for this behaviour.

Comment on lines 523 to 527
CopyStmt *stmt = castNode(CopyStmt, parsetree);
char *filename = stmt->filename;
if (!is_absolute_path(filename))
ereport(ERROR, (errcode(ERRCODE_INVALID_NAME), errmsg("relative path not allowed for COPY to file")));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to the MakeDuckdbCopyQuery function? Also relative paths should still be allowed for reading, just not for writing. That's what posgres does.

Copy link
Contributor Author

@ggnmstr ggnmstr Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me looks more reasonable to this part of code to IsAllowedStatement, is that ok?

Copy link
Collaborator

@JelteF JelteF Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sounds good (I'm assuming you mean the IsAllowedStatement function in src/utility/copy.cpp, because there's also one in pgduckdb_hooks.cpp)

@JelteF JelteF added this to the 1.0.0 milestone Jun 17, 2025
@JelteF JelteF enabled auto-merge (squash) July 31, 2025 08:18
@JelteF JelteF merged commit bcf3c56 into duckdb:main Jul 31, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants