Skip to content
Advertisement

postgres syntax error on grant select on table

I have a query:

            DROP TABLE IF EXISTS abc;
            CREATE TABLE abc AS
            SELECT title            
            FROM people
            WHERE title like 'ram%'           
            GRANT SELECT ON abc IN SCHEMA public TO ram;

But on running this: I get the following syntax error:

(psycopg2.errors.SyntaxError) syntax error at or near "IN"
LINE 26:         GRANT SELECT ON abc IN SCHEMA publi...

without grant query its working fine.

What am I missing here?

Advertisement

Answer

To specify the schema, use ON public.abc.
The syntax IN SCHEMA public can only be used with ON ALL TABLES.

Also, you have to separate CREATE TABLE and GRANT with a semicolon, as they are two separate statements.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement