bug with long serial names
Apologies if this has been raised before.
This:
create table a12345678901234567890 ( b1234567890 serial );
causes this:
pqReadData() -- backend closed the channel unexpectedly.
This probably means the backend terminated abnormally before or
while processing the request.
We have lost the connection to the backend, so further processing is
impossible. Terminating.
This is on postgres 6.4.1 (the "fixed" 6.4.1, not the accidental
snapshot) on BSDI.
The same problem exists in 6.4 on FreeBSD.
create table a12345678901234567890 ( b1234567890 serial );
causes this:
pqReadData() -- backend closed the channel unexpectedly.
I hadn't heard about this. Will look at it. In the meantime, don't do
that :)
The upper limit on names is probably something like
<table name length> + <column name length> + 5 <= 31
- Tom
create table a12345678901234567890 ( b1234567890 serial );
causes this:
pqReadData() -- backend closed the channel unexpectedly.The upper limit on names is probably something like
<table name length> + <column name length> + 5 <= 31
Here is a patch which should catch the problem:
pg=> create table a12345678901234567890 ( b1234567890 serial );
ERROR: CREATE TABLE/SERIAL implicit sequence name must be less than 32
characters
Sum of lengths of 'a12345678901234567890' and 'b1234567890' must
be less than 27
Will be in the next release. Apply the patch by putting it into the
backend/parser/ directory, then typing:
patch < analyze.c.patch
btw, the patch should apply cleanly but with offsets since my source
code has some other changes you will not want (yet).
- Tom
Attachments:
analyze.c.patchtext/plain; charset=us-ascii; name=analyze.c.patchDownload
*** analyze.c.orig Wed Dec 9 05:22:34 1998
--- analyze.c Tue Dec 29 18:24:44 1998
***************
*** 535,540 ****
--- 533,542 ----
CreateSeqStmt *sequence;
sname = makeTableName(stmt->relname, column->colname, "seq", NULL);
+ if (sname == NULL)
+ elog(ERROR, "CREATE TABLE/SERIAL implicit sequence name must be less than %d characters"
+ "\n\tSum of lengths of '%s' and '%s' must be less than %d",
+ NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-5));
constraint = makeNode(Constraint);
constraint->contype = CONSTR_DEFAULT;
***************
*** 563,568 ****
--- 565,574 ----
constraint = makeNode(Constraint);
constraint->contype = CONSTR_UNIQUE;
constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
+ if (constraint->name == NULL)
+ elog(ERROR, "CREATE TABLE/SERIAL implicit index name must be less than %d characters"
+ "\n\tSum of lengths of '%s' and '%s' must be less than %d",
+ NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-5));
column->constraints = lappend(column->constraints, constraint);
}
***************
*** 584,589 ****
--- 590,605 ----
constraint = lfirst(clist);
switch (constraint->contype)
{
+ case CONSTR_NULL:
+ /* We should mark this explicitly,
+ * so we can tell if NULL and NOT NULL are both specified
+ */
+ if (column->is_not_null)
+ elog(ERROR, "CREATE TABLE/(NOT) NULL conflicting declaration"
+ " for %s.%s", stmt->relname, column->colname);
+ column->is_not_null = FALSE;
+ break;
+
case CONSTR_NOTNULL:
if (column->is_not_null)
elog(ERROR, "CREATE TABLE/NOT NULL already specified"
***************
*** 601,606 ****
--- 617,626 ----
case CONSTR_PRIMARY:
if (constraint->name == NULL)
constraint->name = makeTableName(stmt->relname, "pkey", NULL);
+ if (constraint->name == NULL)
+ elog(ERROR, "CREATE TABLE/PRIMARY KEY implicit index name must be less than %d characters"
+ "\n\tLength of '%s' must be less than %d",
+ NAMEDATALEN, stmt->relname, (NAMEDATALEN-6));
if (constraint->keys == NIL)
constraint->keys = lappend(constraint->keys, column);
dlist = lappend(dlist, constraint);
***************
*** 609,614 ****
--- 629,638 ----
case CONSTR_UNIQUE:
if (constraint->name == NULL)
constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
+ if (constraint->name == NULL)
+ elog(ERROR, "CREATE TABLE/UNIQUE implicit index name must be less than %d characters"
+ "\n\tLength of '%s' must be less than %d",
+ NAMEDATALEN, stmt->relname, (NAMEDATALEN-5));
if (constraint->keys == NIL)
constraint->keys = lappend(constraint->keys, column);
dlist = lappend(dlist, constraint);
***************
*** 618,623 ****
--- 642,651 ----
constraints = lappend(constraints, constraint);
if (constraint->name == NULL)
constraint->name = makeTableName(stmt->relname, column->colname, NULL);
+ if (constraint->name == NULL)
+ elog(ERROR, "CREATE TABLE/CHECK implicit constraint name must be less than %d characters"
+ "\n\tSum of lengths of '%s' and '%s' must be less than %d",
+ NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-1));
break;
default:
***************
*** 636,641 ****
--- 664,673 ----
case CONSTR_PRIMARY:
if (constraint->name == NULL)
constraint->name = makeTableName(stmt->relname, "pkey", NULL);
+ if (constraint->name == NULL)
+ elog(ERROR, "CREATE TABLE/PRIMARY KEY implicit index name must be less than %d characters"
+ "\n\tLength of '%s' must be less than %d",
+ NAMEDATALEN, stmt->relname, (NAMEDATALEN-5));
dlist = lappend(dlist, constraint);
break;
***************
*** 709,714 ****
--- 741,750 ----
have_pkey = TRUE;
index->idxname = makeTableName(stmt->relname, "pkey", NULL);
+ if (index->idxname == NULL)
+ elog(ERROR, "CREATE TABLE/PRIMARY KEY implicit index name must be less than %d characters"
+ "\n\tLength of '%s' must be less than %d",
+ NAMEDATALEN, stmt->relname, (NAMEDATALEN-5));
}
else
index->idxname = NULL;
Hi,
This appears to have worked, but required a patch to your patch -- which I've attached.
The new version passes regression tests in a manner very similar to the old,
so I'm assuming all is well, here, and that you mistakenly sent me one
of the features I'm not ready for yet... (CONSTR_NULL was undefined).
I'm just a novice here, so please, please, correct it if necessary!
Thanks very much for the quick service!
*** analyze.c 1998/12/29 18:43:50 1.2
--- analyze.c 1998/12/29 18:48:53
***************
*** 7,13 ****
*
*
* IDENTIFICATION
! * $Header: /usr/local/ports/databases/postgres-6.4.1/work/postgresql-6.4.1/src/backend/parser/RCS/analyze.c,v 1.2 1998/12/29 18:43:50 pgsql Exp $
*
*-------------------------------------------------------------------------
*/
--- 7,13 ----
*
*
* IDENTIFICATION
! * $Header: /usr/local/ports/databases/postgres-6.4.1/work/postgresql-6.4.1/src/backend/parser/RCS/analyze.c,v 1.3 1998/12/29 18:48:50 pgsql Exp $
*
*-------------------------------------------------------------------------
*/
***************
*** 592,606 ****
constraint = lfirst(clist);
switch (constraint->contype)
{
- case CONSTR_NULL:
- /* We should mark this explicitly,
- * so we can tell if NULL and NOT NULL are both specified
- */
- if (column->is_not_null)
- elog(ERROR, "CREATE TABLE/(NOT) NULL conflicting declaration"
- " for %s.%s", stmt->relname, column->colname);
- column->is_not_null = FALSE;
- break;
case CONSTR_NOTNULL:
if (column->is_not_null)
--- 592,597 ----
Import Notes
Resolved by subject fallback