Error in Table Creation

Started by Rajnish Vishwakarmaalmost 6 years ago3 messagesgeneral
Jump to latest
#1Rajnish Vishwakarma
rajnish.nationfirst@gmail.com

I am creating dynamically table in PostgreSQL using psycopg2 by passing the
below 2 strings as column names:

'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load_in_PA_load'

and

'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load__in_TA_load'

And the above column names are not same ( both are different columns ) and
both the columns has string same till
*'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load__
.*

but i am getting errors as

Error:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/table_creation_with_HDA_Data.py",
line 131, in <module>
cursor.execute(sqlCreateTable)
psycopg2.errors.DuplicateColumn: column
"BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_"
specified more than once

The above columns are of type TEXT ...also it may be Numeric Type in future.

Require assistance from Postgres team on the above error.

Thanks
Rajnish Vishwakarma

#2Guillaume Lelarge
guillaume@lelarge.info
In reply to: Rajnish Vishwakarma (#1)
Re: Error in Table Creation

Le jeu. 25 juin 2020 à 10:59, Rajnish Vishwakarma <
rajnish.nationfirst@gmail.com> a écrit :

I am creating dynamically table in PostgreSQL using psycopg2 by passing
the below 2 strings as column names:

'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load_in_PA_load'

and

'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load__in_TA_load'

And the above column names are not same ( both are different columns ) and
both the columns has string same till *'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load__
.*

but i am getting errors as

Error:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/table_creation_with_HDA_Data.py", line 131, in <module>
cursor.execute(sqlCreateTable)
psycopg2.errors.DuplicateColumn: column "BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_" specified more than once

The above columns are of type TEXT ...also it may be Numeric Type in
future.

Require assistance from Postgres team on the above error.

Object names in PostgreSQL are limited to 63 characters. If you put more
characters, it will silently truncate them to 63 characters. In your case,
they are truncated, and the truncated strings end up being the same. So,
use less characters for your objects' names.

#3Magnus Hagander
magnus@hagander.net
In reply to: Rajnish Vishwakarma (#1)
Re: Error in Table Creation

On Thu, Jun 25, 2020 at 10:59 AM Rajnish Vishwakarma <
rajnish.nationfirst@gmail.com> wrote:

I am creating dynamically table in PostgreSQL using psycopg2 by passing
the below 2 strings as column names:

'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load_in_PA_load'

and

'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load__in_TA_load'

And the above column names are not same ( both are different columns ) and
both the columns has string same till *'BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_with_metal_temp_TC_load__
.*

but i am getting errors as

Error:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/table_creation_with_HDA_Data.py", line 131, in <module>
cursor.execute(sqlCreateTable)
psycopg2.errors.DuplicateColumn: column "BAF7_X_X_During_soaking-__Temperature__difference_coil_to_coil_" specified more than once

The above columns are of type TEXT ...also it may be Numeric Type in
future.

Require assistance from Postgres team on the above error.

By default the maximum length of a column name (or other names) in postgres
is 63 characters, see
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS).
You are trying to create columns with names that are way longer than that,
so they will be truncated. If you create this table in psql it will show
you a NOTICE information about this -- I believe in psycopg2 this shows up
in conn.noticies (where conn is the connection object from psycopg2).

And truncated to 63 characters they *are* the same name. (Those are some
crazy long column names btw..)

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/&gt;
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/&gt;