Skip to content

Commit 3722dee

Browse files
committed
Document function args are required for pg_restore -P.
Fix pg_dump to not quote the function name in the storage tag. Fix pg_dump so GRANT/REVOKE(ACL) tag entries are not quoted, for consistency. Fix pg_restore to properly handle quotes and some spaces in -P.
1 parent d656c24 commit 3722dee

File tree

4 files changed

+116
-49
lines changed

4 files changed

+116
-49
lines changed

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.25 2002/05/10 22:36:26 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.26 2002/07/04 03:04:54 momjian Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<docinfo>
@@ -33,7 +33,7 @@
3333
<arg> -L <replaceable class="parameter">contents-file</replaceable> </arg>
3434
<group> <arg> -N </arg> <arg> -o </arg> <arg> -r </arg> </group>
3535
<arg> -O </arg>
36-
<arg> -P <replaceable class="parameter">function-name</replaceable> </arg>
36+
<arg> -P <replaceable class="parameter">function-name(argtype [, ...])</replaceable> </arg>
3737
<arg> -R </arg>
3838
<arg> -s </arg>
3939
<arg> -S </arg>
@@ -276,8 +276,8 @@
276276
</varlistentry>
277277

278278
<varlistentry>
279-
<term><option>-P <replaceable class="parameter">function-name</replaceable></option></term>
280-
<term><option>--function=<replaceable class="parameter">function-name</replaceable></option></term>
279+
<term><option>-P <replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>
280+
<term><option>--function=<replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>
281281
<listitem>
282282
<para>
283283
Specify a procedure or function to be restored.

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.50 2002/07/02 05:49:51 momjian Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.51 2002/07/04 03:04:54 momjian Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -191,6 +191,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
191191
* initially connected to, not the one we will create, which is very
192192
* bad...
193193
*/
194+
194195
if (ropt->create && ropt->noReconnect)
195196
die_horribly(AH, modulename, "-C and -R are incompatible options\n");
196197

src/bin/pg_dump/pg_dump.c

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.268 2002/07/02 05:49:51 momjian Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.269 2002/07/04 03:04:54 momjian Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -104,14 +104,14 @@ static void dumpTableACL(Archive *fout, TableInfo *tbinfo);
104104
static void dumpFuncACL(Archive *fout, FuncInfo *finfo);
105105
static void dumpAggACL(Archive *fout, AggInfo *finfo);
106106
static void dumpACL(Archive *fout, const char *type, const char *name,
107-
const char *nspname, const char *usename,
108-
const char *acl, const char *objoid);
107+
const char *name_noquotes, const char *nspname,
108+
const char *usename, const char *acl, const char *objoid);
109109

110110
static void dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables);
111111
static void dumpRules(Archive *fout, TableInfo *tblinfo, int numTables);
112112
static void formatStringLiteral(PQExpBuffer buf, const char *str,
113113
const formatLiteralOptions opts);
114-
static char *format_function_signature(FuncInfo *finfo);
114+
static char *format_function_signature(FuncInfo *finfo, bool honor_quotes);
115115
static void dumpOneFunc(Archive *fout, FuncInfo *finfo);
116116
static void dumpOneOpr(Archive *fout, OprInfo *oprinfo,
117117
OprInfo *g_oprinfo, int numOperators);
@@ -2721,7 +2721,7 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
27212721
if (strcmp(nspinfo->nspname, "public") == 0)
27222722
{
27232723
if (!aclsSkip && strcmp(nspinfo->nspacl, "{=UC}") != 0)
2724-
dumpACL(fout, "SCHEMA", qnspname, NULL,
2724+
dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
27252725
nspinfo->usename, nspinfo->nspacl,
27262726
nspinfo->oid);
27272727
}
@@ -2747,7 +2747,7 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
27472747
nspinfo->oid, "pg_namespace", 0, NULL);
27482748

27492749
if (!aclsSkip)
2750-
dumpACL(fout, "SCHEMA", qnspname, NULL,
2750+
dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
27512751
nspinfo->usename, nspinfo->nspacl,
27522752
nspinfo->oid);
27532753
}
@@ -3291,8 +3291,9 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs)
32913291

32923292
if (!aclsSkip)
32933293
{
3294-
char * tmp = strdup(fmtId(lanname, force_quotes));
3295-
dumpACL(fout, "LANGUAGE", tmp, finfo[fidx].pronamespace->nspname,
3294+
char *tmp = strdup(fmtId(lanname, force_quotes));
3295+
dumpACL(fout, "LANGUAGE", tmp, lanname,
3296+
finfo[fidx].pronamespace->nspname,
32963297
NULL, lanacl, lanoid);
32973298
free(tmp);
32983299
}
@@ -3333,13 +3334,16 @@ dumpFuncs(Archive *fout, FuncInfo finfo[], int numFuncs)
33333334
* is never qualified.
33343335
*/
33353336
static char *
3336-
format_function_signature(FuncInfo *finfo)
3337+
format_function_signature(FuncInfo *finfo, bool honor_quotes)
33373338
{
33383339
PQExpBufferData fn;
33393340
int j;
33403341

33413342
initPQExpBuffer(&fn);
3342-
appendPQExpBuffer(&fn, "%s (", fmtId(finfo->proname, force_quotes));
3343+
if (honor_quotes)
3344+
appendPQExpBuffer(&fn, "%s(", fmtId(finfo->proname, force_quotes));
3345+
else
3346+
appendPQExpBuffer(&fn, "%s(", finfo->proname);
33433347
for (j = 0; j < finfo->nargs; j++)
33443348
{
33453349
char *typname;
@@ -3358,12 +3362,15 @@ format_function_signature(FuncInfo *finfo)
33583362
static void
33593363
dumpFuncACL(Archive *fout, FuncInfo *finfo)
33603364
{
3361-
char *funcsig;
3365+
char *funcsig, *funcsig_noquotes;
33623366

3363-
funcsig = format_function_signature(finfo);
3364-
dumpACL(fout, "FUNCTION", funcsig, finfo->pronamespace->nspname,
3367+
funcsig = format_function_signature(finfo, true);
3368+
funcsig_noquotes = format_function_signature(finfo, false);
3369+
dumpACL(fout, "FUNCTION", funcsig, funcsig_noquotes,
3370+
finfo->pronamespace->nspname,
33653371
finfo->usename, finfo->proacl, finfo->oid);
33663372
free(funcsig);
3373+
free(funcsig_noquotes);
33673374
}
33683375

33693376

@@ -3380,6 +3387,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
33803387
PQExpBuffer asPart = createPQExpBuffer();
33813388
PGresult *res = NULL;
33823389
char *funcsig = NULL;
3390+
char *funcsig_noquotes = NULL;
33833391
int ntups;
33843392
char *proretset;
33853393
char *prosrc;
@@ -3487,7 +3495,8 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
34873495
}
34883496
}
34893497

3490-
funcsig = format_function_signature(finfo);
3498+
funcsig = format_function_signature(finfo, true);
3499+
funcsig_noquotes = format_function_signature(finfo, false);
34913500

34923501
/* DROP must be fully qualified in case same name appears in pg_catalog */
34933502
appendPQExpBuffer(delqry, "DROP FUNCTION %s.%s;\n",
@@ -3517,7 +3526,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
35173526
finfo->proname);
35183527
exit_nicely();
35193528
}
3520-
}
3529+
}
35213530

35223531
if (proimplicit[0] == 't')
35233532
appendPQExpBuffer(q, " IMPLICIT CAST");
@@ -3530,7 +3539,8 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
35303539

35313540
appendPQExpBuffer(q, ";\n");
35323541

3533-
ArchiveEntry(fout, finfo->oid, funcsig, finfo->pronamespace->nspname,
3542+
ArchiveEntry(fout, finfo->oid, funcsig_noquotes,
3543+
finfo->pronamespace->nspname,
35343544
finfo->usename, "FUNCTION", NULL,
35353545
q->data, delqry->data,
35363546
NULL, NULL, NULL);
@@ -3551,6 +3561,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
35513561
destroyPQExpBuffer(delqry);
35523562
destroyPQExpBuffer(asPart);
35533563
free(funcsig);
3564+
free(funcsig_noquotes);
35543565
}
35553566

35563567
/*
@@ -3939,14 +3950,17 @@ dumpAggs(Archive *fout, AggInfo agginfo[], int numAggs)
39393950
* is never qualified.
39403951
*/
39413952
static char *
3942-
format_aggregate_signature(AggInfo *agginfo, Archive *fout)
3953+
format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
39433954
{
39443955
PQExpBufferData buf;
39453956
bool anybasetype;
39463957

39473958
initPQExpBuffer(&buf);
3948-
appendPQExpBuffer(&buf, "%s",
3959+
if (honor_quotes)
3960+
appendPQExpBuffer(&buf, "%s",
39493961
fmtId(agginfo->aggname, force_quotes));
3962+
else
3963+
appendPQExpBuffer(&buf, "%s", agginfo->aggname);
39503964

39513965
anybasetype = (strcmp(agginfo->aggbasetype, "0") == 0);
39523966

@@ -3974,12 +3988,15 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout)
39743988
static void
39753989
dumpAggACL(Archive *fout, AggInfo *finfo)
39763990
{
3977-
char *aggsig;
3991+
char *aggsig, *aggsig_noquotes;
39783992

3979-
aggsig = format_aggregate_signature(finfo, fout);
3980-
dumpACL(fout, "FUNCTION", aggsig, finfo->aggnamespace->nspname,
3993+
aggsig = format_aggregate_signature(finfo, fout, true);
3994+
aggsig_noquotes = format_aggregate_signature(finfo, fout, false);
3995+
dumpACL(fout, "FUNCTION", aggsig, aggsig_noquotes,
3996+
finfo->aggnamespace->nspname,
39813997
finfo->usename, finfo->aggacl, finfo->oid);
39823998
free(aggsig);
3999+
free(aggsig_noquotes);
39834000
}
39844001

39854002

@@ -3994,7 +4011,8 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
39944011
PQExpBuffer q = createPQExpBuffer();
39954012
PQExpBuffer delq = createPQExpBuffer();
39964013
PQExpBuffer details = createPQExpBuffer();
3997-
char *aggSig;
4014+
char *aggsig;
4015+
char *aggsig_noquotes;
39984016
PGresult *res;
39994017
int ntups;
40004018
int i_aggtransfn;
@@ -4084,16 +4102,17 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
40844102
agginfo->fmtbasetype = strdup(PQgetvalue(res, 0, i_fmtbasetype));
40854103
convertok = (PQgetvalue(res, 0, i_convertok)[0] == 't');
40864104

4087-
aggSig = format_aggregate_signature(agginfo, g_fout);
4105+
aggsig = format_aggregate_signature(agginfo, g_fout, true);
4106+
aggsig_noquotes = format_aggregate_signature(agginfo, g_fout, false);
40884107

40894108
if (!convertok)
40904109
{
40914110
write_msg(NULL, "WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n",
4092-
aggSig);
4111+
aggsig);
40934112

40944113
appendPQExpBuffer(q, "-- WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n",
4095-
aggSig);
4096-
ArchiveEntry(fout, agginfo->oid, aggSig,
4114+
aggsig);
4115+
ArchiveEntry(fout, agginfo->oid, aggsig_noquotes,
40974116
agginfo->aggnamespace->nspname, agginfo->usename,
40984117
"WARNING", NULL,
40994118
q->data, "" /* Del */ ,
@@ -4146,13 +4165,13 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
41464165
/* DROP must be fully qualified in case same name appears in pg_catalog */
41474166
appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
41484167
fmtId(agginfo->aggnamespace->nspname, force_quotes),
4149-
aggSig);
4168+
aggsig);
41504169

41514170
appendPQExpBuffer(q, "CREATE AGGREGATE %s ( %s );\n",
41524171
fmtId(agginfo->aggname, force_quotes),
41534172
details->data);
41544173

4155-
ArchiveEntry(fout, agginfo->oid, aggSig,
4174+
ArchiveEntry(fout, agginfo->oid, aggsig_noquotes,
41564175
agginfo->aggnamespace->nspname, agginfo->usename,
41574176
"AGGREGATE", NULL,
41584177
q->data, delq->data,
@@ -4161,7 +4180,7 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
41614180
/*** Dump Aggregate Comments ***/
41624181

41634182
resetPQExpBuffer(q);
4164-
appendPQExpBuffer(q, "AGGREGATE %s", aggSig);
4183+
appendPQExpBuffer(q, "AGGREGATE %s", aggsig);
41654184
if (g_fout->remoteVersion >= 70300)
41664185
dumpComment(fout, q->data,
41674186
agginfo->aggnamespace->nspname, agginfo->usename,
@@ -4177,7 +4196,8 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
41774196
destroyPQExpBuffer(q);
41784197
destroyPQExpBuffer(delq);
41794198
destroyPQExpBuffer(details);
4180-
free(aggSig);
4199+
free(aggsig);
4200+
free(aggsig_noquotes);
41814201
}
41824202

41834203

@@ -4276,7 +4296,7 @@ GetPrivileges(Archive *AH, const char *s, const char *type)
42764296
*/
42774297
static void
42784298
dumpACL(Archive *fout, const char *type, const char *name,
4279-
const char *nspname, const char *usename,
4299+
const char *name_noquotes, const char *nspname, const char *usename,
42804300
const char *acls, const char *objoid)
42814301
{
42824302
char *aclbuf,
@@ -4390,7 +4410,7 @@ dumpACL(Archive *fout, const char *type, const char *name,
43904410
appendPQExpBuffer(sql, "%s;\n", fmtId(usename, force_quotes));
43914411
}
43924412

4393-
ArchiveEntry(fout, objoid, name, nspname, usename ? usename : "",
4413+
ArchiveEntry(fout, objoid, name_noquotes, nspname, usename ? usename : "",
43944414
"ACL", NULL, sql->data, "", NULL, NULL, NULL);
43954415

43964416
free(aclbuf);
@@ -4401,9 +4421,9 @@ dumpACL(Archive *fout, const char *type, const char *name,
44014421
static void
44024422
dumpTableACL(Archive *fout, TableInfo *tbinfo)
44034423
{
4404-
char * tmp = strdup( fmtId(tbinfo->relname, force_quotes) );
4405-
dumpACL(fout, "TABLE", tmp, tbinfo->relnamespace->nspname,
4406-
tbinfo->usename, tbinfo->relacl,
4424+
char *tmp = strdup(fmtId(tbinfo->relname, force_quotes));
4425+
dumpACL(fout, "TABLE", tmp, tbinfo->relname,
4426+
tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relacl,
44074427
tbinfo->viewoid != NULL ? tbinfo->viewoid : tbinfo->oid);
44084428
free(tmp);
44094429
}
@@ -5793,20 +5813,17 @@ myFormatType(const char *typname, int32 typmod)
57935813
precision, scale);
57945814
}
57955815
}
5796-
57975816
/*
57985817
* char is an internal single-byte data type; Let's make sure we force
57995818
* it through with quotes. - thomas 1998-12-13
58005819
*/
58015820
else if (!strcmp(typname, "char"))
58025821
{
5803-
appendPQExpBuffer(buf, "%s",
5804-
fmtId(typname, true));
5822+
appendPQExpBuffer(buf, "%s", fmtId(typname, true));
58055823
}
58065824
else
58075825
{
5808-
appendPQExpBuffer(buf, "%s",
5809-
fmtId(typname, false));
5826+
appendPQExpBuffer(buf, "%s", fmtId(typname, false));
58105827
}
58115828

58125829
result = strdup(buf->data);

0 commit comments

Comments
 (0)