Fix bug caused by the wrong usage of appendStringInfo().
authorShigeru Hanada <[email protected]>
Fri, 19 Nov 2010 01:35:49 +0000 (10:35 +0900)
committerShigeru Hanada <[email protected]>
Fri, 19 Nov 2010 01:35:49 +0000 (10:35 +0900)
contrib/postgresql_fdw/postgresql_fdw.c

index b6fd2eff973ef763ac2f9dba405a90f42b34b90b..16cfe150d9449896ab61778ae2312beca73778bf 100644 (file)
@@ -254,7 +254,7 @@ deparseSelectClause(StringInfo sql, ForeignTable *table, TupleDesc tupdesc,
    aliasname_q = quote_identifier(aliasname);
 
    /* deparse SELECT clause */
-   appendStringInfo(sql, "SELECT ");
+   appendStringInfoString(sql, "SELECT ");
 
    /*
     * TODO: omit (deparse to "NULL") columns which are not used in the
@@ -302,7 +302,7 @@ deparseSelectClause(StringInfo sql, ForeignTable *table, TupleDesc tupdesc,
 
    /* if target list is composed only of system attributes, add dummy column */
    if (first)
-       appendStringInfo(sql, "NULL");
+       appendStringInfoString(sql, "NULL");
 
    if (aliasname_q != aliasname)
        pfree((char *) aliasname_q);
@@ -325,9 +325,6 @@ deparseFromClause(StringInfo sql, ForeignTable *table, const char *aliasname, bo
    /* The alias of relation is used in both SELECT clause and FROM clause. */
    aliasname_q = quote_identifier(aliasname);
 
-   /* deparse FROM clause */
-   appendStringInfo(sql, " FROM ");
-
    /*
     * If the foreign table has generic option "nspname" and/or "relname", use
     * them in the foreign query.  Otherwise, use local catalog names.
@@ -347,7 +344,7 @@ deparseFromClause(StringInfo sql, ForeignTable *table, const char *aliasname, bo
        relname = get_rel_name(table->relid);
    nspname_q = quote_identifier(nspname);
    relname_q = quote_identifier(relname);
-   appendStringInfo(sql, "%s.%s %s", nspname_q, relname_q, aliasname_q);
+   appendStringInfo(sql, " FROM %s.%s %s", nspname_q, relname_q, aliasname_q);
    pfree(nspname);
    pfree(relname);
    if (nspname_q != nspname)
@@ -452,8 +449,7 @@ deparseSql(ForeignScanState *scanstate)
        {
            Node   *node;
            node = (Node *) make_ands_explicit(foreign_expr);
-           appendStringInfo(&sql, " WHERE ");
-           appendStringInfo(&sql,
+           appendStringInfo(&sql, " WHERE %s",
                deparse_expression(node, context, prefix, false));
            /*
             * The contents of the list MUST NOT be free-ed because they are