I there a way to copy the existing schema and generate new schema with another name in the same database in postgres.
标签:
postgresql
相关问题
- Django distinct is not working
- PostgreSQL: left outer join syntax
- Connecting Python to a Heroku PostgreSQL DB?
- PostgreSQL - Deleting data that are older than an
- Does PLV8 support making http calls to other serve
相关文章
- postgresql 关于使用between and 中是字符串的问题
- postgresql 月份差计算问题
- Using boolean expression in order by clause
- Table valued Parameter Equivalent in Postgresql
- in redshift postgresql can I skip columns with the
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- PostgreSQL field data type for IPv4 addresses
- Using prepared statement in stored function
TEMPLATE
option to create a copy:CREATE DATABASE dbname_target TEMPLATE dbname_source;
${schema_name}
with your new schema name, and then execute this script on the database. In this way if you make a changes to thisschema
, you can also have scripts to update the schema to a new version, which you will have to do for every user schema in this case.I ran a few tests and found the result is referencing the source schema. So here's my improved version:
In the case you are OK with only tables and columns (without constraints, keys etc.) this simple script could be helpful
Check out this PostgreSQL's wiki page. It contains a function for
clone_schema
as you required, but this function only clones tables. The page refers to this post, which contains a function that clones everything you need for the schema. This function worked well for me, I managed to execute it with JDBC API.But I had some problems when the schema names contained
-
or capital letters. After a research I found out that the source of the problem isquote_ident()
method. I changes theclone_schema
function to work with any schema names. I share the new function here, hope it will help somebody:Using @IdanDavidi's solution, I was able to solve the case where sequences were owned by and referring to the source schema instead of the destination schema.
You can use this simple script :