ERROR Relation already exists in PostgreSQL when creating an index on a table

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 ?

Answers


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.


Need Your Help

UIImage screenshot loses its quality

iphone objective-c ios xcode uiimage

I am merging two images and then I take a screenshot by applying this code:

SSCrypto/OpenSSL to C# Crypto

c# .net cocoa encryption openssl

Has anyone been able to use the SSCrypto Framework for Cocoa to encrypt text and then decrypt it in C#/.NET ? Or can someone offer some guidance?