From 1fd9883ff49fdc4008c6a17936441b74696ff1a9 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 26 Dec 2009 16:55:21 +0000 Subject: [PATCH] Zero-label enums: Allow enums to be created with zero labels, for use during binary upgrade. --- doc/src/sgml/ref/create_type.sgml | 4 ++-- src/backend/parser/gram.y | 11 ++++++++--- src/bin/pg_dump/pg_dump.c | 8 +------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/doc/src/sgml/ref/create_type.sgml b/doc/src/sgml/ref/create_type.sgml index 78b11b8a80..cb264127c2 100644 --- a/doc/src/sgml/ref/create_type.sgml +++ b/doc/src/sgml/ref/create_type.sgml @@ -1,5 +1,5 @@ @@ -25,7 +25,7 @@ CREATE TYPE name AS ( attribute_name data_type [, ... ] ) CREATE TYPE name AS ENUM - ( 'label' [, ... ] ) + ( [ 'label' [, ... ] ] ) CREATE TYPE name ( INPUT = input_function, diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 30663d578e..333b65bb9e 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.699 2009/12/23 17:41:43 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.700 2009/12/26 16:55:21 momjian Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -297,7 +297,7 @@ static TypeName *TableFuncTypeName(List *columns); TableFuncElementList opt_type_modifiers prep_type_clause execute_param_clause using_clause returning_clause - enum_val_list table_func_column_list + opt_enum_val_list enum_val_list table_func_column_list create_generic_options alter_generic_options relation_expr_list dostmt_opt_list @@ -3623,7 +3623,7 @@ DefineStmt: n->coldeflist = $6; $$ = (Node *)n; } - | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')' + | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')' { CreateEnumStmt *n = makeNode(CreateEnumStmt); n->typeName = $3; @@ -3715,6 +3715,11 @@ old_aggr_elem: IDENT '=' def_arg } ; +opt_enum_val_list: + enum_val_list { $$ = $1; } + | /*EMPTY*/ { $$ = NIL; } + ; + enum_val_list: Sconst { $$ = list_make1(makeString($1)); } | enum_val_list ',' Sconst diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 47d2c4fcf4..037c7045e5 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.561 2009/12/24 22:09:23 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.562 2009/12/26 16:55:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -6542,12 +6542,6 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK); num = PQntuples(res); - /* should be at least 1 value */ - if (num == 0) - { - write_msg(NULL, "no label definitions found for enum ID %u\n", tyinfo->dobj.catId.oid); - exit_nicely(); - } /* * DROP must be fully qualified in case same name appears in pg_catalog. -- 2.40.0