0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

PostgreSQL does not support GRANT syntax during CREATE TABLE command. You'll need to separate them.

For the GRANT, you will be better off prefixing the table name with schema (i.e., public.abc), as IN SCHEMA syntax is not supported unless you're GRANTing ON ALL TABLES. Here's a full working example:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.