

If the column has already the good name (here cust_date_mean), the rename command that must be applied only on the wrong name should be properly skipped and not issuing the following error: db_1 | ERROR: column "cust_mean" does not existĭb_1 | STATEMENT: ALTER TABLE tablename RENAME COLUMN cust_mean TO cust_date_mean ĭb_1 | ERROR: column "cust_mean" does not exist Hence the idea of using an IF EXISTS statement on the column name while trying to rename it. I would be glad we could, because I'm facing an error that depends on who made and gave me an SQL script, for which in some cases everything is perfectly fine (when the column has the wrong name, name that will actually be changed using a RENAME statement), and in other cases not (when the column already has the right name). name : Create tbl2 in the acme database with the DDL like tbl1 with testuser as an owner postgresql_table : db : acme name : tbl2 like : tbl1 owner : testuser - name : Create tbl2 in the acme database and tablespace ssd with the DDL like tbl1 including comments and indexes postgresql_table : db : acme table : tbl2 like : tbl1 including : comments, indexes tablespace : ssd - name : Create test_table with several columns in ssd tablespace with fillfactor=10 and autovacuum_analyze_threshold=1 postgresql_table : name : test_table columns : - id bigserial primary key - num bigint - stories text tablespace : ssd storage_params : - fillfactor=10 - autovacuum_analyze_threshold=1 - name : Create an unlogged table in schema acme postgresql_table : name : eless_data columns : waste_id int unlogged : true - name : Rename table foo to bar postgresql_table : table : foo rename : bar - name : Rename table foo from schema acme to bar postgresql_table : name : acme.foo rename : bar - name : Set owner to someuser postgresql_table : name : foo owner : someuser - name : Change tablespace of foo table to new_tablespace and set owner to new_user postgresql_table : name : foo tablespace : new_tablespace owner : new_user - name : Truncate table foo postgresql_table : name : foo truncate : yes - name : Drop table foo from schema acme postgresql_table : name : acme.I couldn't find in the PostgreSQL documentation if there is a way to run an: ALTER TABLE tablename RENAME COLUMN IF EXISTS colname TO newcolname statement. PostgreSQL data typesĬomplete reference of the PostgreSQL data types documentation. DROP TABLE referenceĬomplete reference of the DROP TABLE command documentation. ALTER TABLE referenceĬomplete reference of the ALTER TABLE command documentation. CREATE TABLE referenceĬomplete reference of the CREATE TABLE command documentation.
The official documentation on the postgresql_copy module. postgresql_copy – Copy data between a file/program and a PostgreSQL table The official documentation on the postgresql_privs module. postgresql_privs – Grant or revoke privileges on PostgreSQL database objects The official documentation on the postgresql_owner module. postgresql_owner – Change an owner of PostgreSQL database object The official documentation on the postgresql_tablespace module. postgresql_tablespace – Add or remove PostgreSQL tablespaces from remote hosts The official documentation on the postgresql_info module. postgresql_info – Gather information about PostgreSQL servers The official documentation on the postgresql_sequence module. See also postgresql_sequence – Create, drop, or alter a PostgreSQL sequence
