Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc29ae52

Browse files
committed
Remove plpgsql's RENAME declaration, which has bizarre and mostly nonfunctional
behavior, and is so little used that no one has been interested in fixing it.To ensure that possible uses are covered, remove the ALIAS declaration'sarbitrary restriction that only $n identifiers can be aliased.(We could alternatively make RENAME act just like ALIAS, but per discussionhaving two different ways to do the same thing is probably more confusing thanhelpful.)
1 parent8e79277 commitc29ae52

File tree

7 files changed

+48
-111
lines changed

7 files changed

+48
-111
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.143 2009/09/29 20:05:29 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.144 2009/11/05 16:58:36 tgl Exp $ -->
22

33
<chapter id="plpgsql">
44
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -135,7 +135,7 @@
135135
and <type>anyenum</>. The actual
136136
data types handled by a polymorphic function can vary from call to
137137
call, as discussed in <xref linkend="extend-types-polymorphic">.
138-
An example is shown in <xref linkend="plpgsql-declaration-aliases">.
138+
An example is shown in <xref linkend="plpgsql-declaration-parameters">.
139139
</para>
140140

141141
<para>
@@ -163,7 +163,7 @@
163163

164164
<para>
165165
Specific examples appear in
166-
<xref linkend="plpgsql-declaration-aliases"> and
166+
<xref linkend="plpgsql-declaration-parameters"> and
167167
<xref linkend="plpgsql-statements-returning">.
168168
</para>
169169
</sect2>
@@ -353,8 +353,8 @@ user_id CONSTANT integer := 10;
353353
</programlisting>
354354
</para>
355355

356-
<sect2 id="plpgsql-declaration-aliases">
357-
<title>Aliases for Function Parameters</title>
356+
<sect2 id="plpgsql-declaration-parameters">
357+
<title>Declaring Function Parameters</title>
358358

359359
<para>
360360
Parameters passed to functions are named with the identifiers
@@ -401,7 +401,7 @@ $$ LANGUAGE plpgsql;
401401
These two examples are not perfectly equivalent. In the first case,
402402
<literal>subtotal</> could be referenced as
403403
<literal>sales_tax.subtotal</>, but in the second case it could not.
404-
(Had we attached a label to the block, <literal>subtotal</> could
404+
(Had we attached a label to theinnerblock, <literal>subtotal</> could
405405
be qualified with that label, instead.)
406406
</para>
407407
</note>
@@ -532,6 +532,38 @@ $$ LANGUAGE plpgsql;
532532
</para>
533533
</sect2>
534534

535+
<sect2 id="plpgsql-declaration-alias">
536+
<title><literal>ALIAS</></title>
537+
538+
<synopsis>
539+
<replaceable>newname</> ALIAS FOR <replaceable>oldname</>;
540+
</synopsis>
541+
542+
<para>
543+
The <literal>ALIAS</> syntax is more general than is suggested in the
544+
previous section: you can declare an alias for any variable, not just
545+
function parameters. The main practical use for this is to assign
546+
a different name for variables with predetermined names, such as
547+
<varname>NEW</varname> or <varname>OLD</varname> within
548+
a trigger procedure.
549+
</para>
550+
551+
<para>
552+
Examples:
553+
<programlisting>
554+
DECLARE
555+
prior ALIAS FOR old;
556+
updated ALIAS FOR new;
557+
</programlisting>
558+
</para>
559+
560+
<para>
561+
Since <literal>ALIAS</> creates two different ways to name the same
562+
object, unrestricted use can be confusing. It's best to use it only
563+
for the purpose of overriding predetermined names.
564+
</para>
565+
</sect2>
566+
535567
<sect2 id="plpgsql-declaration-type">
536568
<title>Copying Types</title>
537569

@@ -664,39 +696,6 @@ SELECT merge_fields(t.*) FROM table1 t WHERE ... ;
664696
structure on-the-fly.
665697
</para>
666698
</sect2>
667-
668-
<sect2 id="plpgsql-declaration-renaming-vars">
669-
<title><literal>RENAME</></title>
670-
671-
<synopsis>
672-
RENAME <replaceable>oldname</replaceable> TO <replaceable>newname</replaceable>;
673-
</synopsis>
674-
675-
<para>
676-
Using the <literal>RENAME</literal> declaration you can change the
677-
name of a variable, record or row. This is primarily useful if
678-
<varname>NEW</varname> or <varname>OLD</varname> should be
679-
referenced by another name inside a trigger procedure. See also
680-
<literal>ALIAS</literal>.
681-
</para>
682-
683-
<para>
684-
Examples:
685-
<programlisting>
686-
RENAME id TO user_id;
687-
RENAME this_var TO that_var;
688-
</programlisting>
689-
</para>
690-
691-
<note>
692-
<para>
693-
<literal>RENAME</literal> appears to be broken as of
694-
<productname>PostgreSQL</> 7.3. Fixing this is of low priority,
695-
since <literal>ALIAS</literal> covers most of the practical uses
696-
of <literal>RENAME</literal>.
697-
</para>
698-
</note>
699-
</sect2>
700699
</sect1>
701700

702701
<sect1 id="plpgsql-expressions">

‎src/pl/plpgsql/src/gram.y

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.129 2009/11/04 22:26:07 tgl Exp $
12+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.130 2009/11/05 16:58:36 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -128,7 +128,6 @@ static List*read_raise_options(void);
128128

129129
%type<declhdr>decl_sect
130130
%type<varname>decl_varname
131-
%type<str>decl_renname
132131
%type<boolean>decl_constdecl_notnullexit_type
133132
%type<expr>decl_defvaldecl_cursor_query
134133
%type<dtype>decl_datatype
@@ -218,7 +217,6 @@ static List*read_raise_options(void);
218217
%tokenK_PERFORM
219218
%tokenK_ROW_COUNT
220219
%tokenK_RAISE
221-
%tokenK_RENAME
222220
%tokenK_RESULT_OID
223221
%tokenK_RETURN
224222
%tokenK_REVERSE
@@ -382,10 +380,6 @@ decl_statement: decl_varname decl_const decl_datatype decl_notnull decl_defval
382380
plpgsql_ns_additem($4->itemtype,
383381
$4->itemno, $1.name);
384382
}
385-
|K_RENAMEdecl_rennameK_TOdecl_renname';'
386-
{
387-
plpgsql_ns_rename($2, $4);
388-
}
389383
|decl_varnameopt_scrollableK_CURSOR
390384
{ plpgsql_ns_push($1.name); }
391385
decl_cursor_argsdecl_is_fordecl_cursor_query
@@ -521,9 +515,8 @@ decl_aliasitem: any_identifier
521515
char*name;
522516
PLpgSQL_nsitem *nsi;
523517

518+
/* XXX should allow block-label-qualified names*/
524519
plpgsql_convert_ident($1, &name,1);
525-
if (name[0] !='$')
526-
yyerror("only positional parameters can be aliased");
527520

528521
plpgsql_ns_setlocal(false);
529522

@@ -532,8 +525,8 @@ decl_aliasitem: any_identifier
532525
{
533526
plpgsql_error_lineno = plpgsql_scanner_lineno();
534527
ereport(ERROR,
535-
(errcode(ERRCODE_UNDEFINED_PARAMETER),
536-
errmsg("function has no parameter\"%s\"",
528+
(errcode(ERRCODE_UNDEFINED_OBJECT),
529+
errmsg("variable\"%s\" does not exist",
537530
name)));
538531
}
539532

@@ -573,17 +566,6 @@ decl_varname: T_WORD
573566
}
574567
;
575568

576-
/* XXX this is broken because it doesn't allow for T_SCALAR,T_ROW,T_RECORD*/
577-
decl_renname:T_WORD
578-
{
579-
char*name;
580-
581-
plpgsql_convert_ident(yytext, &name,1);
582-
/* the result must be palloc'd, see plpgsql_ns_rename*/
583-
$$ = name;
584-
}
585-
;
586-
587569
decl_const:
588570
{$$ =false; }
589571
|K_CONSTANT

‎src/pl/plpgsql/src/pl_funcs.c

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.82 2009/11/04 22:26:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.83 2009/11/05 16:58:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -235,48 +235,6 @@ plpgsql_ns_lookup_label(const char *name)
235235
}
236236

237237

238-
/* ----------
239-
* plpgsql_ns_renameRename a namespace entry
240-
* ----------
241-
*/
242-
void
243-
plpgsql_ns_rename(char*oldname,char*newname)
244-
{
245-
PLpgSQL_ns*ns;
246-
PLpgSQL_nsitem*newitem;
247-
inti;
248-
249-
/*
250-
* Lookup name in the namestack
251-
*/
252-
for (ns=ns_current;ns!=NULL;ns=ns->upper)
253-
{
254-
for (i=1;i<ns->items_used;i++)
255-
{
256-
if (strcmp(ns->items[i]->name,oldname)==0)
257-
{
258-
newitem=palloc(sizeof(PLpgSQL_nsitem)+strlen(newname));
259-
newitem->itemtype=ns->items[i]->itemtype;
260-
newitem->itemno=ns->items[i]->itemno;
261-
strcpy(newitem->name,newname);
262-
263-
pfree(oldname);
264-
pfree(newname);
265-
266-
pfree(ns->items[i]);
267-
ns->items[i]=newitem;
268-
return;
269-
}
270-
}
271-
}
272-
273-
ereport(ERROR,
274-
(errcode(ERRCODE_UNDEFINED_OBJECT),
275-
errmsg("variable \"%s\" does not exist in the current block",
276-
oldname)));
277-
}
278-
279-
280238
/* ----------
281239
* plpgsql_convert_ident
282240
*

‎src/pl/plpgsql/src/plpgsql.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.118 2009/11/04 22:26:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.119 2009/11/05 16:58:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -287,7 +287,7 @@ typedef struct
287287
{/* Item in the compilers namestack*/
288288
intitemtype;
289289
intitemno;
290-
charname[1];
290+
charname[1];/* actually, as long as needed */
291291
}PLpgSQL_nsitem;
292292

293293

@@ -851,7 +851,6 @@ extern void plpgsql_ns_additem(int itemtype, int itemno, const char *name);
851851
externPLpgSQL_nsitem*plpgsql_ns_lookup(constchar*name1,constchar*name2,
852852
constchar*name3,int*names_used);
853853
externPLpgSQL_nsitem*plpgsql_ns_lookup_label(constchar*name);
854-
externvoidplpgsql_ns_rename(char*oldname,char*newname);
855854

856855
/* ----------
857856
* Other functions in pl_funcs.c

‎src/pl/plpgsql/src/scan.l

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.72 2009/09/29 20:05:29 tgl Exp $
12+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.73 2009/11/05 16:58:36 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -183,7 +183,6 @@ open{ return K_OPEN;}
183183
or{return K_OR;}
184184
perform{return K_PERFORM;}
185185
raise{return K_RAISE;}
186-
rename{return K_RENAME;}
187186
result_oid{return K_RESULT_OID;}
188187
return{return K_RETURN;}
189188
reverse{return K_REVERSE;}

‎src/test/regress/expected/plpgsql.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ create trigger tg_pfield_ad after delete
162162
create function tg_pslot_biu() returns trigger as $proc$
163163
declare
164164
pfrecrecord;
165-
rename new to ps;
165+
ps alias for new;
166166
begin
167167
select into pfrec * from PField where name = ps.pfname;
168168
if not found then

‎src/test/regress/sql/plpgsql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ create trigger tg_pfield_ad after delete
211211
createfunctiontg_pslot_biu() returns triggeras $proc$
212212
declare
213213
pfrecrecord;
214-
rename new to ps;
214+
ps alias for new;
215215
begin
216216
select into pfrec*from PFieldwhere name=ps.pfname;
217217
if not found then

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp