Обсуждение: Error when creating a char column as primary key
Hi folks, Complete novice here! I am trying to create a table as; CREATE TABLE table (serial_no VARCHAR[16] PRIMARY KEY, date date DEFAULT current_date) when I issue this command postgres returns an error saying; ERROR: Can't find a default operator class for type 1015 I tried this as well; CREATE TABLE table (serial_no VARCHAR[16] PRIMARY KEY NOT NULL, date date DEFAULT current_date) but I get the same error. I guess that postgres is telling me that if there is no default value then you can't assign a primary key to the column. Is this the case or is there a work around that I can use without assigning a SERIAL type to another column as the primary key? Thanks, greadey **************************************************************************** The information contained in this email is intended only for the use of the intended recipient at the email address to which it has been addressed. If the reader of this message is not an intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination or copying of the message or associated attachments is strictly prohibited. If you have received this email in error, please contact the sender by return email or call 01793 877777 and ask for the sender and then delete it immediately from your system. Please note that neither Innogy nor the sender accepts any responsibility for viruses and it is your responsibility to scan attachments (if any). *****************************************************************************
use VARCHAR(16) and not VARCHAR[16]. hth Devinder Rajput Stores Division Corporate Offices Chicago, IL (773) 442-6474 "Gavin Reade" <gavin.reade@innogy.co To: "'pgsql-novice@postgresql.org'" <pgsql-novice@postgresql.org> m> cc: Sent by: Subject: [NOVICE] Error when creating a char column as primary key pgsql-novice-owner@pos tgresql.org 11/21/2002 09:26 AM Hi folks, Complete novice here! I am trying to create a table as; CREATE TABLE table (serial_no VARCHAR[16] PRIMARY KEY, date date DEFAULT current_date) when I issue this command postgres returns an error saying; ERROR: Can't find a default operator class for type 1015 I tried this as well; CREATE TABLE table (serial_no VARCHAR[16] PRIMARY KEY NOT NULL, date date DEFAULT current_date) but I get the same error. I guess that postgres is telling me that if there is no default value then you can't assign a primary key to the column. Is this the case or is there a work around that I can use without assigning a SERIAL type to another column as the primary key? Thanks, greadey **************************************************************************** The information contained in this email is intended only for the use of the intended recipient at the email address to which it has been addressed. If the reader of this message is not an intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination or copying of the message or associated attachments is strictly prohibited. If you have received this email in error, please contact the sender by return email or call 01793 877777 and ask for the sender and then delete it immediately from your system. Please note that neither Innogy nor the sender accepts any responsibility for viruses and it is your responsibility to scan attachments (if any). ***************************************************************************** ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
"Devinder K Rajput" <Devinder.Rajput@ipaper.com> writes: >> CREATE TABLE table (serial_no VARCHAR[16] PRIMARY KEY, date date DEFAULT >> current_date) >> ERROR: Can't find a default operator class for type 1015 > use VARCHAR(16) and not VARCHAR[16]. Also, consider updating to a more recent version of Postgres. It's been a very long time since that error message gave a numeric type OID. In 7.2 and later I get regression=# CREATE TABLE ztable (serial_no VARCHAR[16] PRIMARY KEY); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'ztable_pkey' for table 'ztable' ERROR: data type character varying[] has no default operator class for access method "btree" You must specify an operator class for the index or define a default operator class for the data type which at least gives you some shot at realizing that you've specified an array type ... regards, tom lane