Re: in PostgreSQL 9.0.2 / pgAdmin III - ERROR: relation "[table name]" already exists - Mailing list pgsql-novice

From Mark Kelly
Subject Re: in PostgreSQL 9.0.2 / pgAdmin III - ERROR: relation "[table name]" already exists
Date
Msg-id 201012251539.28830.pgsql@wastedtimes.net
Whole thread Raw
In response to in PostgreSQL 9.0.2 / pgAdmin III - ERROR: relation "[table name]" already exists  (thewhitelantern <thewhitelantern@gmail.com>)
List pgsql-novice
Hi.

On Saturday 25 Dec 2010 at 15:10 thewhitelantern wrote:

[snip]

> However, I'm called to put a WHERE filter on the code at the end
>
> WHERE
>   id = 524
> ;
>
> THen when I try to execute it again, it gives this error message
>
> ERROR:  relation "entries" already exists

I suspect that you are running ALL of the code above again, with the "WHERE"
clause appended. What you actually need to do is ONLY run the SELECT
instruction again. The error is because you are trying to create the table
(called a "relation" in this context) again.

Instead of running the whole lot again the second time, just run the query:

SELECT
  title
, category
FROM
  entries
WHERE
  id = 524
;

All the stuff before that only has to be done once.

> So does this mean that I have to delete the database EVERY TIME I CHANGE
>  THE CODE?!?

No :)

Cheers,

Mark

pgsql-novice by date:

Previous
From: thewhitelantern
Date:
Subject: in PostgreSQL 9.0.2 / pgAdmin III - ERROR: relation "[table name]" already exists
Next
From: Lew
Date:
Subject: Re: Problem with select statement for duplicate data