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

Commiteaeb407

Browse files
committed
Keep all Consts as expressions while deparsing.
($n placeholders will be filled with evaluated value when sending the query).This allows to prepare 'generic' (with placeholders) queries on the remote sideand later reuse them.
1 parent9728fb2 commiteaeb407

File tree

1 file changed

+19
-87
lines changed

1 file changed

+19
-87
lines changed

‎contrib/postgres_fdw/deparse.c‎

Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,99 +2247,31 @@ deparseVar(Var *node, deparse_expr_cxt *context)
22472247
staticvoid
22482248
deparseConst(Const*node,deparse_expr_cxt*context,intshowtype)
22492249
{
2250-
StringInfobuf=context->buf;
2251-
Oidtypoutput;
2252-
booltypIsVarlena;
2253-
char*extval;
2254-
boolisfloat= false;
2255-
boolneedlabel;
2256-
2257-
if (node->constisnull)
2250+
if (context->params_list)
22582251
{
2259-
appendStringInfoString(buf,"NULL");
2260-
if (showtype >=0)
2261-
appendStringInfo(buf,"::%s",
2262-
deparse_type_name(node->consttype,
2263-
node->consttypmod));
2264-
return;
2265-
}
2252+
intpindex=0;
2253+
ListCell*lc;
22662254

2267-
getTypeOutputInfo(node->consttype,
2268-
&typoutput,&typIsVarlena);
2269-
extval=OidOutputFunctionCall(typoutput,node->constvalue);
2255+
/* find its index in params_list */
2256+
foreach(lc,*context->params_list)
2257+
{
2258+
pindex++;
2259+
if (equal(node, (Node*)lfirst(lc)))
2260+
break;
2261+
}
2262+
if (lc==NULL)
2263+
{
2264+
/* not in list, so add it */
2265+
pindex++;
2266+
*context->params_list=lappend(*context->params_list,node);
2267+
}
22702268

2271-
switch (node->consttype)
2272-
{
2273-
caseINT2OID:
2274-
caseINT4OID:
2275-
caseINT8OID:
2276-
caseOIDOID:
2277-
caseFLOAT4OID:
2278-
caseFLOAT8OID:
2279-
caseNUMERICOID:
2280-
{
2281-
/*
2282-
* No need to quote unless it's a special value such as 'NaN'.
2283-
* See comments in get_const_expr().
2284-
*/
2285-
if (strspn(extval,"0123456789+-eE.")==strlen(extval))
2286-
{
2287-
if (extval[0]=='+'||extval[0]=='-')
2288-
appendStringInfo(buf,"(%s)",extval);
2289-
else
2290-
appendStringInfoString(buf,extval);
2291-
if (strcspn(extval,"eE.")!=strlen(extval))
2292-
isfloat= true;/* it looks like a float */
2293-
}
2294-
else
2295-
appendStringInfo(buf,"'%s'",extval);
2296-
}
2297-
break;
2298-
caseBITOID:
2299-
caseVARBITOID:
2300-
appendStringInfo(buf,"B'%s'",extval);
2301-
break;
2302-
caseBOOLOID:
2303-
if (strcmp(extval,"t")==0)
2304-
appendStringInfoString(buf,"true");
2305-
else
2306-
appendStringInfoString(buf,"false");
2307-
break;
2308-
default:
2309-
deparseStringLiteral(buf,extval);
2310-
break;
2269+
printRemoteParam(pindex,node->consttype,node->consttypmod,context);
23112270
}
2312-
2313-
pfree(extval);
2314-
2315-
if (showtype<0)
2316-
return;
2317-
2318-
/*
2319-
* For showtype == 0, append ::typename unless the constant will be
2320-
* implicitly typed as the right type when it is read in.
2321-
*
2322-
* XXX this code has to be kept in sync with the behavior of the parser,
2323-
* especially make_const.
2324-
*/
2325-
switch (node->consttype)
2271+
else
23262272
{
2327-
caseBOOLOID:
2328-
caseINT4OID:
2329-
caseUNKNOWNOID:
2330-
needlabel= false;
2331-
break;
2332-
caseNUMERICOID:
2333-
needlabel= !isfloat|| (node->consttypmod >=0);
2334-
break;
2335-
default:
2336-
needlabel= true;
2337-
break;
2273+
printRemotePlaceholder(node->consttype,node->consttypmod,context);
23382274
}
2339-
if (needlabel||showtype>0)
2340-
appendStringInfo(buf,"::%s",
2341-
deparse_type_name(node->consttype,
2342-
node->consttypmod));
23432275
}
23442276

23452277
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp