ThunderSpark
ThunderSpark

Reputation: 183

How to resolve pgadmin 4 GRANT syntax error in this query?

I am currently busy trying to execute some SQL queries form my demonstratie of a PostgreSQL/Postgis database. However I get a syntax on a certain line in my query.

This query did work in the past on a different computer so I do not see the problem here of why it does not work now:

CREATE ROLE demonstratieuser NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
CREATE ROLE demonstratieadmin NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
GRANT demonstratieuser TO demonstratieadmin
GRANT ALL ON DATABASE demodatabase TO demonstratieadmin

It is the following line that has the syntax error on more specifically the Grant part.

GRANT ALL ON DATABASE demodatabase TO demonstratieadmin

How do I fix this?

Edit error code:

ERROR:  syntax error at or near "GRANT"
LINE 4: GRANT ALL ON DATABASE demodatabase TO demonstratieadmin;
        ^
********** Error **********

ERROR: syntax error at or near "GRANT"
SQL state: 42601
Character: 222

Upvotes: 1

Views: 1715

Answers (1)

Rahul
Rahul

Reputation: 77876

That's cause you are missing a ; semicolon in the below line which is line terminator.

GRANT demonstratieuser TO demonstratieadmin

So it should actually be

CREATE ROLE demonstratieuser NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
CREATE ROLE demonstratieadmin NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
GRANT demonstratieuser TO demonstratieadmin;
GRANT ALL ON DATABASE demodatabase TO demonstratieadmin;

Upvotes: 1

Related Questions