Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a6697b3

Browse files
committed
get_seq_name should truncate name to NAMEDATALEN, so that this works:
create sequence a1234567890123456789012345678901234567890; select nextval('a1234567890123456789012345678901234567890');
1 parent b67fc00 commit a6697b3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/backend/commands/sequence.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.57 2001/06/01 19:52:24 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.58 2001/06/06 22:03:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,6 +22,10 @@
2222
#include "miscadmin.h"
2323
#include "utils/acl.h"
2424
#include "utils/builtins.h"
25+
#ifdef MULTIBYTE
26+
#include "mb/pg_wchar.h"
27+
#endif
28+
2529

2630
#define SEQ_MAGIC 0x1717
2731

@@ -523,7 +527,8 @@ setval_and_iscalled(PG_FUNCTION_ARGS)
523527

524528
/*
525529
* Given a 'text' parameter to a sequence function, extract the actual
526-
* sequence name. We downcase the name if it's not double-quoted.
530+
* sequence name. We downcase the name if it's not double-quoted,
531+
* and truncate it if it's too long.
527532
*
528533
* This is a kluge, really --- should be able to write nextval(seqrel).
529534
*/
@@ -557,6 +562,20 @@ get_seq_name(text *seqin)
557562
*rawname = tolower((unsigned char) *rawname);
558563
}
559564
}
565+
566+
/* Truncate name if it's overlength; again, should match scan.l */
567+
if (strlen(seqname) >= NAMEDATALEN)
568+
{
569+
#ifdef MULTIBYTE
570+
int len;
571+
572+
len = pg_mbcliplen(seqname, i, NAMEDATALEN-1);
573+
seqname[len] = '\0';
574+
#else
575+
seqname[NAMEDATALEN-1] = '\0';
576+
#endif
577+
}
578+
560579
return seqname;
561580
}
562581

0 commit comments

Comments
 (0)