i needed to restore specific table, backed up via pg_dump, to the same database / schema but under different name. that’s what i’ve done
pv dump.zstd|pzstd -dc - |sed 's/name_of_original_table/name_of_renamed_table/g'|su - postgres -c 'psql dbname'
this only works if all constrains / indices have in their name name of the original table.
This approach to restoring a PostgreSQL dump into a differently named table is quite practical, especially for quick testing or development work. However, it also feels a bit risky if used in production environments due to potential conflicts or unintended replacements. Are there safer built-in PostgreSQL methods that can handle table renaming during restore?
maybe, but i’m not aware of them.