|
7 | 7 | * Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.64 2003/07/04 02:51:33 tgl Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.65 2003/07/17 20:13:57 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -403,21 +403,39 @@ CommentDatabase(List *qualname, char *comment)
|
403 | 403 | elog(ERROR, "CommentDatabase: database name may not be qualified");
|
404 | 404 | database = strVal(lfirst(qualname));
|
405 | 405 |
|
| 406 | + /* |
| 407 | + * We cannot currently support cross-database comments (since other DBs |
| 408 | + * cannot see pg_description of this database). So, we reject attempts |
| 409 | + * to comment on a database other than the current one. Someday this |
| 410 | + * might be improved, but it would take a redesigned infrastructure. |
| 411 | + * |
| 412 | + * When loading a dump, we may see a COMMENT ON DATABASE for the old name |
| 413 | + * of the database. Erroring out would prevent pg_restore from completing |
| 414 | + * (which is really pg_restore's fault, but for now we will work around |
| 415 | + * the problem here). Consensus is that the best fix is to treat wrong |
| 416 | + * database name as a WARNING not an ERROR. |
| 417 | + */ |
| 418 | + |
406 | 419 | /* First get the database OID */
|
407 | 420 | oid = get_database_oid(database);
|
408 | 421 | if (!OidIsValid(oid))
|
409 |
| - elog(ERROR, "database \"%s\" does not exist", database); |
| 422 | + { |
| 423 | + elog(WARNING, "database \"%s\" does not exist", database); |
| 424 | + return; |
| 425 | + } |
410 | 426 |
|
411 |
| - /* Allow if the user matches the database dba or is a superuser */ |
| 427 | + /* Only allow comments on the current database */ |
| 428 | + if (oid != MyDatabaseId) |
| 429 | + { |
| 430 | + elog(WARNING, "database comments may only be applied to the current database"); |
| 431 | + return; |
| 432 | + } |
412 | 433 |
|
| 434 | + /* Allow if the user matches the database dba or is a superuser */ |
413 | 435 | if (!pg_database_ownercheck(oid, GetUserId()))
|
414 | 436 | elog(ERROR, "you are not permitted to comment on database \"%s\"",
|
415 | 437 | database);
|
416 | 438 |
|
417 |
| - /* Only allow comments on the current database */ |
418 |
| - if (oid != MyDatabaseId) |
419 |
| - elog(ERROR, "Database comments may only be applied to the current database"); |
420 |
| - |
421 | 439 | /* Create the comment with the pg_database oid */
|
422 | 440 | CreateComments(oid, RelOid_pg_database, 0, comment);
|
423 | 441 | }
|
|
0 commit comments