4

I have an error when running the the queries below on PostgreSQL from a Java code

 .....
 sql =  "CREATE TABLE IF NOT EXISTS table1 (s VARCHAR(100), p VARCHAR(100), o VARCHAR(100), PRIMARY KEY (s,p,o)) ; ";                   
 pgsql.runUpdateQuery(sql);         

 sql =  "CREATE INDEX indextable1 ON table1 (s,p,o);";  
 pgsql.runUpdateQuery(sql);         
 .....

But i got the following Error

org.postgresql.util.PSQLException: ERROR: relation "indextable1" already exists         

Can someone explain me what its happening? My understanding is that PRIMARY KEY is consider to be an INDEX and therefore the second query fail. Am I right ?

2
  • 3
    There is another index (or table) named indextable1 in your schema. It has nothing to do with the fact that the column list is already indexed. Commented Jan 30, 2014 at 15:42
  • @a_horse_with_no_name thanks, I've clean-up all the database before running again queries, now everything gone well. Commented Jan 30, 2014 at 16:49

1 Answer 1

3

The problem is that the primary key constraint name is equal the table name. I don know how postgres represents constraints, but I think the error "Relation already exists" was being triggered during the creation of the primary key constraint because the table was already declared. But because of this error, the table wasnt created at the end.

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

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.