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

Commitaa38434

Browse files
committed
Refactor routines for name lookups of procedures and operators
This introduces a new set of extended routines for procedure andoperator name lookups, with a flag bitmask argument that can modify theresult. The following options are available:- Force schema qualification, ignoring search_path. This is similar tothe existing option for format_{operator|procedure}_qualified().- Force NULL as result instead of a numeric OID for an undefinedobject. This option is new.This is a refactoring similar to1185c78, that will be used for a futurepatch to improve the SQL functions providing information using objectaddresses for undefined objects.Author: Michael PaquierReviewed-by: Aleksander Alekseev, Dmitry Dolgov, Daniel Gustafsson,Álvaro HerreraDiscussion:https://postgr.es/m/CAB7nPqSZxrSmdHK-rny7z8mi=EAFXJ5J-0RbzDw6aus=wB5azQ@mail.gmail.com
1 parent04c7f41 commitaa38434

File tree

2 files changed

+56
-20
lines changed

2 files changed

+56
-20
lines changed

‎src/backend/utils/adt/regproc.c

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#include"utils/syscache.h"
4242
#include"utils/varlena.h"
4343

44-
staticchar*format_operator_internal(Oidoperator_oid,boolforce_qualify);
45-
staticchar*format_procedure_internal(Oidprocedure_oid,boolforce_qualify);
4644
staticvoidparseNameAndArgTypes(constchar*string,boolallowNone,
4745
List**names,int*nargs,Oid*argtypes);
4846

@@ -323,24 +321,32 @@ to_regprocedure(PG_FUNCTION_ARGS)
323321
char*
324322
format_procedure(Oidprocedure_oid)
325323
{
326-
returnformat_procedure_internal(procedure_oid,false);
324+
returnformat_procedure_extended(procedure_oid,0);
327325
}
328326

329327
char*
330328
format_procedure_qualified(Oidprocedure_oid)
331329
{
332-
returnformat_procedure_internal(procedure_oid,true);
330+
returnformat_procedure_extended(procedure_oid,FORMAT_PROC_FORCE_QUALIFY);
333331
}
334332

335333
/*
334+
* format_procedure_extended - converts procedure OID to "pro_name(args)"
335+
*
336+
* This exports the useful functionality of regprocedureout for use
337+
* in other backend modules. The result is a palloc'd string, or NULL.
338+
*
336339
* Routine to produce regprocedure names; see format_procedure above.
337340
*
338-
* force_qualify says whether to schema-qualify; if true, the name is always
339-
* qualified regardless of search_path visibility. Otherwise the name is only
340-
* qualified if the function is not in path.
341+
* The following bits in 'flags' modify the behavior:
342+
* - FORMAT_PROC_INVALID_AS_NULL
343+
*if the procedure OID is invalid or unknown, return NULL instead
344+
*of the numeric OID.
345+
* - FORMAT_PROC_FORCE_QUALIFY
346+
*always schema-qualify procedure names, regardless of search_path
341347
*/
342-
staticchar*
343-
format_procedure_internal(Oidprocedure_oid,boolforce_qualify)
348+
char*
349+
format_procedure_extended(Oidprocedure_oid,bits16flags)
344350
{
345351
char*result;
346352
HeapTupleproctup;
@@ -365,7 +371,8 @@ format_procedure_internal(Oid procedure_oid, bool force_qualify)
365371
* Would this proc be found (given the right args) by regprocedurein?
366372
* If not, or if caller requests it, we need to qualify it.
367373
*/
368-
if (!force_qualify&&FunctionIsVisible(procedure_oid))
374+
if ((flags&FORMAT_PROC_FORCE_QUALIFY)==0&&
375+
FunctionIsVisible(procedure_oid))
369376
nspname=NULL;
370377
else
371378
nspname=get_namespace_name(procform->pronamespace);
@@ -379,7 +386,7 @@ format_procedure_internal(Oid procedure_oid, bool force_qualify)
379386
if (i>0)
380387
appendStringInfoChar(&buf,',');
381388
appendStringInfoString(&buf,
382-
force_qualify ?
389+
(flags&FORMAT_PROC_FORCE_QUALIFY)!=0 ?
383390
format_type_be_qualified(thisargtype) :
384391
format_type_be(thisargtype));
385392
}
@@ -389,6 +396,11 @@ format_procedure_internal(Oid procedure_oid, bool force_qualify)
389396

390397
ReleaseSysCache(proctup);
391398
}
399+
elseif ((flags&FORMAT_PROC_INVALID_AS_NULL)!=0)
400+
{
401+
/* If object is undefined, return NULL as wanted by caller */
402+
result=NULL;
403+
}
392404
else
393405
{
394406
/* If OID doesn't match any pg_proc entry, return it numerically */
@@ -747,13 +759,20 @@ to_regoperator(PG_FUNCTION_ARGS)
747759
}
748760

749761
/*
750-
*format_operator- converts operator OID to "opr_name(args)"
762+
*format_operator_extended- converts operator OID to "opr_name(args)"
751763
*
752764
* This exports the useful functionality of regoperatorout for use
753-
* in other backend modules. The result is a palloc'd string.
765+
* in other backend modules. The result is a palloc'd string, or NULL.
766+
*
767+
* The following bits in 'flags' modify the behavior:
768+
* - FORMAT_OPERATOR_INVALID_AS_NULL
769+
*if the operator OID is invalid or unknown, return NULL instead
770+
*of the numeric OID.
771+
* - FORMAT_OPERATOR_FORCE_QUALIFY
772+
*always schema-qualify operator names, regardless of search_path
754773
*/
755-
staticchar*
756-
format_operator_internal(Oidoperator_oid,boolforce_qualify)
774+
char*
775+
format_operator_extended(Oidoperator_oid,bits16flags)
757776
{
758777
char*result;
759778
HeapTupleopertup;
@@ -776,7 +795,8 @@ format_operator_internal(Oid operator_oid, bool force_qualify)
776795
* Would this oper be found (given the right args) by regoperatorin?
777796
* If not, or if caller explicitly requests it, we need to qualify it.
778797
*/
779-
if (force_qualify|| !OperatorIsVisible(operator_oid))
798+
if ((flags&FORMAT_OPERATOR_FORCE_QUALIFY)!=0||
799+
!OperatorIsVisible(operator_oid))
780800
{
781801
nspname=get_namespace_name(operform->oprnamespace);
782802
appendStringInfo(&buf,"%s.",
@@ -787,15 +807,15 @@ format_operator_internal(Oid operator_oid, bool force_qualify)
787807

788808
if (operform->oprleft)
789809
appendStringInfo(&buf,"%s,",
790-
force_qualify ?
810+
(flags&FORMAT_OPERATOR_FORCE_QUALIFY)!=0 ?
791811
format_type_be_qualified(operform->oprleft) :
792812
format_type_be(operform->oprleft));
793813
else
794814
appendStringInfoString(&buf,"NONE,");
795815

796816
if (operform->oprright)
797817
appendStringInfo(&buf,"%s)",
798-
force_qualify ?
818+
(flags&FORMAT_OPERATOR_FORCE_QUALIFY)!=0 ?
799819
format_type_be_qualified(operform->oprright) :
800820
format_type_be(operform->oprright));
801821
else
@@ -805,6 +825,11 @@ format_operator_internal(Oid operator_oid, bool force_qualify)
805825

806826
ReleaseSysCache(opertup);
807827
}
828+
elseif ((flags&FORMAT_OPERATOR_INVALID_AS_NULL)!=0)
829+
{
830+
/* If object is undefined, return NULL as wanted by caller */
831+
result=NULL;
832+
}
808833
else
809834
{
810835
/*
@@ -820,13 +845,14 @@ format_operator_internal(Oid operator_oid, bool force_qualify)
820845
char*
821846
format_operator(Oidoperator_oid)
822847
{
823-
returnformat_operator_internal(operator_oid,false);
848+
returnformat_operator_extended(operator_oid,0);
824849
}
825850

826851
char*
827852
format_operator_qualified(Oidoperator_oid)
828853
{
829-
returnformat_operator_internal(operator_oid, true);
854+
returnformat_operator_extended(operator_oid,
855+
FORMAT_OPERATOR_FORCE_QUALIFY);
830856
}
831857

832858
void

‎src/include/utils/regproc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515

1616
#include"nodes/pg_list.h"
1717

18+
/* Control flags for format_procedure_extended */
19+
#defineFORMAT_PROC_INVALID_AS_NULL0x01/* NULL if undefined */
20+
#defineFORMAT_PROC_FORCE_QUALIFY0x02/* force qualification */
21+
externchar*format_procedure_extended(Oidprocedure_oid,bits16flags);
22+
23+
/* Control flags for format_operator_extended */
24+
#defineFORMAT_OPERATOR_INVALID_AS_NULL0x01/* NULL if undefined */
25+
#defineFORMAT_OPERATOR_FORCE_QUALIFY0x02/* force qualification */
26+
externchar*format_operator_extended(Oidoperator_oid,bits16flags);
27+
1828
externList*stringToQualifiedNameList(constchar*string);
1929
externchar*format_procedure(Oidprocedure_oid);
2030
externchar*format_procedure_qualified(Oidprocedure_oid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp