I am trying:
GRANT CREATE PRIVILEGES ON TABLESPACE NEW_TABLESPACE TO thisuser;
But I receive an error near GRANT. What am I doing wrong?
Main Topics
Browse All TopicsExperts,
I have a script that creates users and assigns them to tablespaces etc. My code below:
I cannot get this script to run in PostgreSQL. It stops on line
DEFAULT TABLESPACE PMD_TABLESPACE with a syntax error but I cannot find the correct syntax.
THanks, Missymadi
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
For 25571485, it is just:
GRANT CREATE ON TABLESPACE NEW_TABLESPACE TO thisuser;
In the documentation for GRANT, the possible follow-ons are "CREATE" or "ALL PRIVILEGES" (where the "PRIVILEGES" is actually optional).
For 25571521, EXECUTE is only used for the execution of prepared statements. See http://www.postgresql.org/
EXECUTE <name> [(param1, ...)]
The optional parameters would be what is passed into the prepared statement.
For that matter, PostgreSQL does not have 'ALTER SESSION'. With a little digging, it looks like the PostgreSQL version of that command would be:
SET SCHEMA 'thisuser'
(This is apparently equivalent to:
SET search_path TO thisuser
)
Check out http://www.postgresql.org/
Are you sure you created the 'test' database? Run this command to check what databases exist:
psql -U <superuser> --list
You should see 3 entries for 'postgres', 'template0' and 'template1'; 'postgres' is the system database, and the templates are just that, templates for new databases. If you do not see "test", then you haven't created that database yet.
If you want to create the database outside of the script, use the 'createdb' command.
Now, if the database name really is "Test", then you have to place the name in double-quotes:
GRANT ALL ON DATABASE "Test" TO thisuser;
If this is the problem, you may want to back up and change the database creation to use lowercase letters, just so this doesn't become a pain later.
OK. I added the quotes and now I'm good to go on that line. The next line was to GRANT CONNECT TO thisuser; and this did not throw an error. The next line was a problem. I tried to look in the postgres manual but I can't get the syntax down. here it is:
GRANT DELETE ON ALL TABLES TO thisuser;
ERROR: syntax error at or near "tables'
I'll answer 25573671 first. The "GRANT ALL ON DATABASE" only allows the CREATE, CONNECT, and TEMP(ORARY) privileges on the database. With CREATE specifically, this only allows creation of new schemas within the database. You then have to perform a "GRANT {CREATE | ALL} ON SCHEMA ..." to allow creation of database objects within a given schema. (On the GRANT page, each privilege section describes its effect for the ON item.) The "public" schema is automatically created in a new database. Table permissions within a database would still have to be granted separately. The exception (or rule) is that the owner of the database immediately has rights for creating objects within that database. And the owners of database objects have rights on operating on those objects (unless revoked).
With 25573591, PostgreSQL's SQL does not have the inherent ability to change the permission of all tables; they have to be done one at a time. Normally, this isn't too much of an imposition; you have to enter the "CREATE TABLE ..." one at a time, so adding a few lines for each additional user that needs access probably isn't too bad. Still, with a little looking I found this web page which describes how to "automate" granting privileges to all tables to a user.
http://www.archonet.com/pg
Business Accounts
Answer for Membership
by: cminearPosted on 2009-10-14 at 07:37:26ID: 25570982
"DEFAULT TABLESPACE", "TEMPORARY TABLESPACE" and "QUOTA" are all invalid options for the CREATE USER command in PostgreSQL, since at least 8.1. See http://www.postgresql.org/ docs/8.4/i nteractive /sql- creat euser.html and http://www.postgresql.org/ docs/8.4/i nteractive /user- mana g.html for more details on adding users (or roles, as they are referred to in PostgreSQL).
docs/8.4/i nteractive /sql- grant .html. (The privileges are limited to "CREATE" and "ALL".
If you want to control the user's access to tablespaces, you need to use GRANT. See http://www.postgresql.org/
PostgreSQL currently does not support quotas.