Answer a question

I've got a import process that copies a table schema with the code below and then populates the table with data. However it doesn't copy over the roles granted.

CREATE TABLE TOTABLE (LIKE FROMTABLE INCLUDING INDEXES)

Is there a way I can copy privileges when the schema is copied, or I can apply the privileges afterwards from the "FROMTABLE"?

Answers

Information about tables in postgresql are stored in the pg_class table. The field containing table privileges is relacl.

So something like the following would work:

update pg_class set relacl = (select relacl from pg_class where relname = 'from_table') where relname='to_table';

Note that pg_class has metadata for all tables -- so you should also take care to make sure you are using the right schema (relnamespace) in case there are tables of the same name in multiple schemas.

Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐