pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Altering multiple column types
8+ messages / 3 participants
[nested] [flat]

* Altering multiple column types
@ 2019-08-02 05:41 Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 06:49 ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 13:53 ` Re: Altering multiple column types Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 8+ messages in thread

From: Bharanee Rathna @ 2019-08-02 05:41 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi,

I'm encountering an issue altering multiple column types in a single ALTER
TABLE

psql (12beta2, server 11.4)
Type "help" for help.
test=# create table users(id serial primary key, name varchar(255),
age int, email varchar(255));
CREATE TABLEtest=# create index users_name_idx on users(name);
CREATE INDEXtest=# create index users_email_idx on users(email);
CREATE INDEXtest=# alter table users alter column name type text,
alter column email type text;
psql: ERROR:  relation "users_name_idx" already exists
test=# alter table users alter column name type text;
ALTER TABLE
test=# alter table users alter column email type text;
ALTER TABLE


Is there a limitation I'm missing in the docs ?

https://www.postgresql.org/docs/11/sql-altertable.html

Thanks

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Altering multiple column types
  2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
@ 2019-08-02 06:49 ` Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 07:43   ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Luca Ferrari @ 2019-08-02 06:49 UTC (permalink / raw)
  To: Bharanee Rathna <deepfryed@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On Fri, Aug 2, 2019 at 7:42 AM Bharanee Rathna <deepfryed@gmail.com> wrote:
>
> Hi,
>
> I'm encountering an issue altering multiple column types in a single ALTER TABLE
>
> psql (12beta2, server 11.4)

it is working on my 11.4 with psql 11.4. Could it be a problem of psql
version 12? Can you try again with a psql "stable"?

testdb=> create table users(id serial primary key, name varchar(255),
age int, email varchar(255));
CREATE TABLE
testdb=> alter table users alter column name type text, alter column
email type text;
ALTER TABLE
testdb=> drop table users;
DROP TABLE
testdb=> create table users(id serial primary key, name varchar(255),
age int, email varchar(255));
CREATE TABLE
testdb=> create index users_email_idx on users(email);
CREATE INDEX
testdb=> alter table users alter column name type text, alter column
email type text;
ALTER TABLE
testdb=> \d users
                            Table "public.users"
 Column |  Type   | Collation | Nullable |              Default
--------+---------+-----------+----------+-----------------------------------
 id     | integer |           | not null | nextval('users_id_seq'::regclass)
 name   | text    |           |          |
 age    | integer |           |          |
 email  | text    |           |          |
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "users_email_idx" btree (email)

testdb=> select version();
                                                version
-------------------------------------------------------------------------------------------------------
 PostgreSQL 11.4 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu
8.3.0-6ubuntu1~18.10.1) 8.3.0, 64-bit
(1 row)





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Altering multiple column types
  2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 06:49 ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
@ 2019-08-02 07:43   ` Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 08:06     ` Re: Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Luca Ferrari @ 2019-08-02 07:43 UTC (permalink / raw)
  To: Bharanee Rathna <deepfryed@gmail.com>; pgsql-general

On Fri, Aug 2, 2019 at 9:39 AM Bharanee Rathna <deepfryed@gmail.com> wrote:
>
> Hi Luca,
>
> I've tried it with a different client and Postgres 10.9, no luck
>
> psql (10.3, server 10.9)

I've fired up a 12beta2 and it works, either with psql 12 or psql 11.4 on linux.
What if you run the statements within another client (pgadmin, a java
client or something else)?

% psql -U postgres testdb
psql (12beta2)
Type "help" for help.

testdb=# create table users(id serial primary key, name varchar(255),
age int, email varchar(255));
CREATE TABLE
testdb=# create index users_email_idx on users(email);
CREATE INDEX
testdb=# alter table users alter column name type text, alter column
email type text;
ALTER TABLE
testdb=# SELECT version();
                                                 version
----------------------------------------------------------------------------------------------------------
 PostgreSQL 12beta2 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu
8.3.0-6ubuntu1~18.10.1) 8.3.0, 64-bit
(1 row)




% ~/git/misc/PostgreSQL/pgenv/pgsql-11.4/bin/psql -U postgres testdb

psql (11.4, server 12beta2)
WARNING: psql major version 11, server major version 12.
         Some psql features might not work.
Type "help" for help.

testdb=# drop table users;
DROP TABLE
testdb=# create table users(id serial primary key, name varchar(255),
age int, email varchar(255));
CREATE TABLE
testdb=# create index users_email_idx on users(email);
CREATE INDEX
testdb=# alter table users alter column name type text, alter column
email type text;
ALTER TABLE





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Altering multiple column types
  2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 06:49 ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 07:43   ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
@ 2019-08-02 08:06     ` Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 08:58       ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Bharanee Rathna @ 2019-08-02 08:06 UTC (permalink / raw)
  To: Luca Ferrari <fluca1978@gmail.com>; +Cc: pgsql-general

Hi Luca,

testing this using docker images. I can replicate it with 10.9-alpine

bash-5.0# psql -h127.0.0.1 -Upostgres test
psql (10.9)
Type "help" for help.

test=# \d users
                                    Table "public.users"
 Column |          Type          | Collation | Nullable |
 Default
--------+------------------------+-----------+----------+-----------------------------------
 id     | integer                |           | not null |
nextval('users_id_seq'::regclass)
 name   | character varying(255) |           |          |
 age    | integer                |           |          |
 email  | character varying(255) |           |          |
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "users_email_idx" btree (email)
    "users_name_idx" btree (name)

test=# alter table users alter column name type text, alter column email
type text;
ERROR:  relation "users_name_idx" already exists

test=# select version();
                                        version

---------------------------------------------------------------------------------------
 PostgreSQL 10.9 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.3.0)
8.3.0, 64-bit
(1 row)


and 11.4

psql (11.4)
Type "help" for help.

test=# \d users
                                    Table "public.users"
 Column |          Type          | Collation | Nullable |
 Default
--------+------------------------+-----------+----------+-----------------------------------
 id     | integer                |           | not null |
nextval('users_id_seq'::regclass)
 name   | character varying(255) |           |          |
 age    | integer                |           |          |
 email  | character varying(255) |           |          |
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "users_email_idx" btree (email)
    "users_name_idx" btree (name)

test=# alter table users alter column name type text, alter column email
type text;
ERROR:  relation "users_name_idx" already exists

test=# select version();
                                        version

---------------------------------------------------------------------------------------
 PostgreSQL 11.4 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.3.0)
8.3.0, 64-bit
(1 row)

Not sure what's going on at my end ...

On Fri, 2 Aug 2019 at 17:44, Luca Ferrari <fluca1978@gmail.com> wrote:

> On Fri, Aug 2, 2019 at 9:39 AM Bharanee Rathna <deepfryed@gmail.com>
> wrote:
> >
> > Hi Luca,
> >
> > I've tried it with a different client and Postgres 10.9, no luck
> >
> > psql (10.3, server 10.9)
>
> I've fired up a 12beta2 and it works, either with psql 12 or psql 11.4 on
> linux.
> What if you run the statements within another client (pgadmin, a java
> client or something else)?
>
> % psql -U postgres testdb
> psql (12beta2)
> Type "help" for help.
>
> testdb=# create table users(id serial primary key, name varchar(255),
> age int, email varchar(255));
> CREATE TABLE
> testdb=# create index users_email_idx on users(email);
> CREATE INDEX
> testdb=# alter table users alter column name type text, alter column
> email type text;
> ALTER TABLE
> testdb=# SELECT version();
>                                                  version
>
> ----------------------------------------------------------------------------------------------------------
>  PostgreSQL 12beta2 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu
> 8.3.0-6ubuntu1~18.10.1) 8.3.0, 64-bit
> (1 row)
>
>
>
>
> % ~/git/misc/PostgreSQL/pgenv/pgsql-11.4/bin/psql -U postgres testdb
>
> psql (11.4, server 12beta2)
> WARNING: psql major version 11, server major version 12.
>          Some psql features might not work.
> Type "help" for help.
>
> testdb=# drop table users;
> DROP TABLE
> testdb=# create table users(id serial primary key, name varchar(255),
> age int, email varchar(255));
> CREATE TABLE
> testdb=# create index users_email_idx on users(email);
> CREATE INDEX
> testdb=# alter table users alter column name type text, alter column
> email type text;
> ALTER TABLE
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Altering multiple column types
  2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 06:49 ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 07:43   ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 08:06     ` Re: Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
@ 2019-08-02 08:58       ` Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 13:18         ` Re: Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Luca Ferrari @ 2019-08-02 08:58 UTC (permalink / raw)
  To: Bharanee Rathna <deepfryed@gmail.com>; +Cc: pgsql-general

On Fri, Aug 2, 2019 at 10:06 AM Bharanee Rathna <deepfryed@gmail.com> wrote:
>
> Hi Luca,
>
> testing this using docker images. I can replicate it with 10.9-alpine
>
> bash-5.0# psql -h127.0.0.1 -Upostgres test
> psql (10.9)
> Type "help" for help.
>
> test=# \d users
>                                     Table "public.users"
>  Column |          Type          | Collation | Nullable |              Default
> --------+------------------------+-----------+----------+-----------------------------------
>  id     | integer                |           | not null | nextval('users_id_seq'::regclass)
>  name   | character varying(255) |           |          |
>  age    | integer                |           |          |
>  email  | character varying(255) |           |          |
> Indexes:
>     "users_pkey" PRIMARY KEY, btree (id)
>     "users_email_idx" btree (email)
>     "users_name_idx" btree (name)

My fault!
I missed one index, so it is working with one index a two column alter
table, but not with two indexes:

testdb=# alter table users alter column name type text, alter column
email type text;
alter table users alter column name type text, alter column email type text;
psql: ERROR:  relation "users_name_idx" already exists


Therefore I think it is a strange behavior, I cannot explain.
I confirm the problem shows up in 11.4 and 12beta2, so I guess there's
must be a reason I don't understand.

Luca





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Altering multiple column types
  2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 06:49 ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 07:43   ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
  2019-08-02 08:06     ` Re: Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 08:58       ` Re: Altering multiple column types Luca Ferrari <fluca1978@gmail.com>
@ 2019-08-02 13:18         ` Bharanee Rathna <deepfryed@gmail.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Bharanee Rathna @ 2019-08-02 13:18 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Thanks for confirming, so I know I'm not going crazy :)

FWIW, it works on 10.3 to 10.8 (I think) and looks like a regression.

psql (10.3 (Debian 10.3-2))
Type "help" for help.

test=# create table users(id serial primary key, name varchar(255), email
varchar(255), age int);
CREATE TABLE
Time: 26.650 ms
test=# create index users_name_idx on users(name); create index
users_email_idx on users(email);
CREATE INDEX
Time: 15.660 ms
CREATE INDEX
Time: 12.065 ms
test=# alter table users alter column name type text, alter column email
type text;
ALTER TABLE
Time: 7.213 ms
test=# select version();

version
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.3 (Debian 10.3-2) on x86_64-pc-linux-gnu, compiled by gcc
(Debian 7.3.0-11) 7.3.0, 64-bit
(1 row)

Time: 2.683 ms

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Altering multiple column types
  2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
@ 2019-08-02 13:53 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-08-02 23:29   ` Re: Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Tom Lane @ 2019-08-02 13:53 UTC (permalink / raw)
  To: Bharanee Rathna <deepfryed@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

Bharanee Rathna <deepfryed@gmail.com> writes:
> I'm encountering an issue altering multiple column types in a single ALTER
> TABLE

Yeah, this is a regression in the May batch of minor releases :-(.
It's fixed for next week's releases.

https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=f946a4091

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Altering multiple column types
  2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
  2019-08-02 13:53 ` Re: Altering multiple column types Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-08-02 23:29   ` Bharanee Rathna <deepfryed@gmail.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Bharanee Rathna @ 2019-08-02 23:29 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@lists.postgresql.org

Thanks Tom!

^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2019-08-02 23:29 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02 05:41 Altering multiple column types Bharanee Rathna <deepfryed@gmail.com>
2019-08-02 06:49 ` Luca Ferrari <fluca1978@gmail.com>
2019-08-02 07:43   ` Luca Ferrari <fluca1978@gmail.com>
2019-08-02 08:06     ` Bharanee Rathna <deepfryed@gmail.com>
2019-08-02 08:58       ` Luca Ferrari <fluca1978@gmail.com>
2019-08-02 13:18         ` Bharanee Rathna <deepfryed@gmail.com>
2019-08-02 13:53 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-02 23:29   ` Bharanee Rathna <deepfryed@gmail.com>

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