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

From: Mark Kelly <pgsql(at)wastedtimes(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: in PostgreSQL 9.0.2 / pgAdmin III - ERROR: relation "[table name]" already exists
Date: 2010-12-25 15:39:28
Message-ID: 201012251539.28830.pgsql@wastedtimes.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Majid Azimi 2010-12-25 17:33:37 Foreign key - index
Previous Message Lew 2010-12-25 15:30:01 Re: in PostgreSQL 9.0.2 / pgAdmin III - ERROR: relation "[table name]" already exists