pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: parthibanp2@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #10316: Alter table rename fails if the "new name" starts with '_'
Date: Wed, 14 May 2014 13:58:50 -0400
Message-ID: <1488.1400090330@sss.pgh.pa.us> (raw)
In-Reply-To: <20140514124119.11846.62730@wrigleys.postgresql.org>
References: <20140514124119.11846.62730@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

parthibanp2@gmail.com writes:
> -- I have created one new table with name t1 

> test=# \d
> No relations found.
> test=# create table t1 (name varchar(10));
> CREATE TABLE

> -- After that i tried to rename 't1' table as '_t1', now the Postgres server
> saying '_t1' is already exists. i'm sure there is no other table in the
> database other than 't1'.

> test=# alter table t1 rename to _t1;
> ERROR:  type "_t1" already exists

Note it's saying *type* _t1 already exists.  This is the internal name
of the type t1[], that is, arrays of the rowtype of t1.  In general,
our convention for the internal name of an array type is to prepend
a _ to the name of its element type.  (There's some logic to choose
a different name if this name is already taken, but that doesn't help
you when it's the array type that got there first.)

> -- Now i renaming table from 't1' to '__t1' and again i renaming from '__t1'
> to '_t1' now its working.

You could have renamed to anything else and then back to _t1; the trick is
just that the table's rowtype and array type have to get renamed out of
the way first.  By and large, though, it's probably best to avoid using
table names that begin with an underscore in PG, since you'll tend to
hit this kind of conflict with rowtype names if you do that.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (2+ messages)

Message-ID: <1488.1400090330@sss.pgh.pa.us>
Permalink:  ../1488.1400090330@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1488.1400090330@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, parthibanp2@gmail.com
  Subject: Re: BUG #10316: Alter table rename fails if the "new name" starts with '_'
  In-Reply-To: <1488.1400090330@sss.pgh.pa.us>
  References: <20140514124119.11846.62730@wrigleys.postgresql.org> <1488.1400090330@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox