Question

I have very little experience in PostgreSQL. I have been reading tutorials and documentation, and in order to create or drop a schema all of them say that I just need to execute:

CREATE SCHEMA myschema; 
DROP SCHEMA myschema; 

but it doesn't work. I finally stumble upon that I have to use:

CREATE SCHEMA myschema AUTHORIZATION pgsql;
DROP SCHEMA myschema RESTRICT;

Do I have a corrupted installation or maybe I added some feature that I shouldn't?

UPDATE: If I use pgAdmin from Mac OS X it works. I don't receive any error or alert of any kind. Basically I just log into pgsql account like this:

su pgsql

then

psql mydatabase
Était-ce utile?

La solution

There are a number of things that can cause commands not to be properly terminated. I believe this answer will help others as well. This may seem too localized but I have heard of it happening to enough beginners it is worth writing up.

In general utility statements like CREATE SCHEMA or DROP SCHEMA will return something in psql, whether an error or a description of what was done. If that doesn't happen something isn't right. The first thing to do is look at the prompt.

The prompt in PostgreSQL is in the form of: [dbname][line-status][is-superuser]

So for a new line, database mydb, nonsuperuser, the prompt looks like: mydb=>

If I am superuser I get:

mydb=#

Now the key character to look at is the one where the = is at. Various symbols have special meanings:

  • = New line (ready for new input)
  • - Continuation from previous line. Did you forget the semicolon?
  • ( In a parenthesis. Your parentheses are unbalanced.
  • $ In a dollar quote block. These are like $quote$string literal$quote$
  • ' Inside a single quoted string literal block
  • " inside a double-quoted identifier

There may be some others but these are the most common. Usually aside from = and -, they are pretty self-explanatory.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top