|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.340 2010/08/13 20:10:51 rhaas Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.341 2010/08/18 18:35:19 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -341,11 +341,21 @@ static const char *storage_name(char c);
|
341 | 341 | * DefineRelation
|
342 | 342 | * Creates a new relation.
|
343 | 343 | *
|
| 344 | + * stmt carries parsetree information from an ordinary CREATE TABLE statement. |
| 345 | + * The other arguments are used to extend the behavior for other cases: |
| 346 | + * relkind: relkind to assign to the new relation |
| 347 | + * ownerId: if not InvalidOid, use this as the new relation's owner. |
| 348 | + * |
| 349 | + * Note that permissions checks are done against current user regardless of |
| 350 | + * ownerId. A nonzero ownerId is used when someone is creating a relation |
| 351 | + * "on behalf of" someone else, so we still want to see that the current user |
| 352 | + * has permissions to do it. |
| 353 | + * |
344 | 354 | * If successful, returns the OID of the new relation.
|
345 | 355 | * ----------------------------------------------------------------
|
346 | 356 | */
|
347 | 357 | Oid
|
348 |
| -DefineRelation(CreateStmt *stmt, char relkind) |
| 358 | +DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) |
349 | 359 | {
|
350 | 360 | char relname[NAMEDATALEN];
|
351 | 361 | Oid namespaceId;
|
@@ -440,6 +450,10 @@ DefineRelation(CreateStmt *stmt, char relkind)
|
440 | 450 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
441 | 451 | errmsg("only shared relations can be placed in pg_global tablespace")));
|
442 | 452 |
|
| 453 | + /* Identify user ID that will own the table */ |
| 454 | + if (!OidIsValid(ownerId)) |
| 455 | + ownerId = GetUserId(); |
| 456 | + |
443 | 457 | /*
|
444 | 458 | * Parse and validate reloptions, if any.
|
445 | 459 | */
|
@@ -532,7 +546,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
|
532 | 546 | InvalidOid,
|
533 | 547 | InvalidOid,
|
534 | 548 | ofTypeId,
|
535 |
| - GetUserId(), |
| 549 | + ownerId, |
536 | 550 | descriptor,
|
537 | 551 | list_concat(cookedDefaults,
|
538 | 552 | old_constraints),
|
|
0 commit comments