@ -384,26 +384,29 @@ static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
static void make_viewdef ( StringInfo buf , HeapTuple ruletup , TupleDesc rulettc ,
static void make_viewdef ( StringInfo buf , HeapTuple ruletup , TupleDesc rulettc ,
int prettyFlags , int wrapColumn ) ;
int prettyFlags , int wrapColumn ) ;
static void get_query_def ( Query * query , StringInfo buf , List * parentnamespace ,
static void get_query_def ( Query * query , StringInfo buf , List * parentnamespace ,
TupleDesc resultDesc ,
TupleDesc resultDesc , bool colNamesVisible ,
int prettyFlags , int wrapColumn , int startIndent ) ;
int prettyFlags , int wrapColumn , int startIndent ) ;
static void get_values_def ( List * values_lists , deparse_context * context ) ;
static void get_values_def ( List * values_lists , deparse_context * context ) ;
static void get_with_clause ( Query * query , deparse_context * context ) ;
static void get_with_clause ( Query * query , deparse_context * context ) ;
static void get_select_query_def ( Query * query , deparse_context * context ,
static void get_select_query_def ( Query * query , deparse_context * context ,
TupleDesc resultDesc ) ;
TupleDesc resultDesc , bool colNamesVisible ) ;
static void get_insert_query_def ( Query * query , deparse_context * context ) ;
static void get_insert_query_def ( Query * query , deparse_context * context ,
static void get_update_query_def ( Query * query , deparse_context * context ) ;
bool colNamesVisible ) ;
static void get_update_query_def ( Query * query , deparse_context * context ,
bool colNamesVisible ) ;
static void get_update_query_targetlist_def ( Query * query , List * targetList ,
static void get_update_query_targetlist_def ( Query * query , List * targetList ,
deparse_context * context ,
deparse_context * context ,
RangeTblEntry * rte ) ;
RangeTblEntry * rte ) ;
static void get_delete_query_def ( Query * query , deparse_context * context ) ;
static void get_delete_query_def ( Query * query , deparse_context * context ,
bool colNamesVisible ) ;
static void get_utility_query_def ( Query * query , deparse_context * context ) ;
static void get_utility_query_def ( Query * query , deparse_context * context ) ;
static void get_basic_select_query ( Query * query , deparse_context * context ,
static void get_basic_select_query ( Query * query , deparse_context * context ,
TupleDesc resultDesc ) ;
TupleDesc resultDesc , bool colNamesVisible ) ;
static void get_target_list ( List * targetList , deparse_context * context ,
static void get_target_list ( List * targetList , deparse_context * context ,
TupleDesc resultDesc ) ;
TupleDesc resultDesc , bool colNamesVisible ) ;
static void get_setop_query ( Node * setOp , Query * query ,
static void get_setop_query ( Node * setOp , Query * query ,
deparse_context * context ,
deparse_context * context ,
TupleDesc resultDesc ) ;
TupleDesc resultDesc , bool colNamesVisible ) ;
static Node * get_rule_sortgroupclause ( Index ref , List * tlist ,
static Node * get_rule_sortgroupclause ( Index ref , List * tlist ,
bool force_colno ,
bool force_colno ,
deparse_context * context ) ;
deparse_context * context ) ;
@ -4897,7 +4900,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
foreach ( action , actions )
foreach ( action , actions )
{
{
query = ( Query * ) lfirst ( action ) ;
query = ( Query * ) lfirst ( action ) ;
get_query_def ( query , buf , NIL , viewResultDesc ,
get_query_def ( query , buf , NIL , viewResultDesc , true ,
prettyFlags , WRAP_COLUMN_DEFAULT , 0 ) ;
prettyFlags , WRAP_COLUMN_DEFAULT , 0 ) ;
if ( prettyFlags )
if ( prettyFlags )
appendStringInfoString ( buf , " ; \n " ) ;
appendStringInfoString ( buf , " ; \n " ) ;
@ -4915,7 +4918,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
Query * query ;
Query * query ;
query = ( Query * ) linitial ( actions ) ;
query = ( Query * ) linitial ( actions ) ;
get_query_def ( query , buf , NIL , viewResultDesc ,
get_query_def ( query , buf , NIL , viewResultDesc , true ,
prettyFlags , WRAP_COLUMN_DEFAULT , 0 ) ;
prettyFlags , WRAP_COLUMN_DEFAULT , 0 ) ;
appendStringInfoChar ( buf , ' ; ' ) ;
appendStringInfoChar ( buf , ' ; ' ) ;
}
}
@ -4989,7 +4992,7 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
ev_relation = table_open ( ev_class , AccessShareLock ) ;
ev_relation = table_open ( ev_class , AccessShareLock ) ;
get_query_def ( query , buf , NIL , RelationGetDescr ( ev_relation ) ,
get_query_def ( query , buf , NIL , RelationGetDescr ( ev_relation ) , true ,
prettyFlags , wrapColumn , 0 ) ;
prettyFlags , wrapColumn , 0 ) ;
appendStringInfoChar ( buf , ' ; ' ) ;
appendStringInfoChar ( buf , ' ; ' ) ;
@ -5000,13 +5003,23 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
/* ----------
/* ----------
* get_query_def - Parse back one query parsetree
* get_query_def - Parse back one query parsetree
*
*
* If resultDesc is not NULL , then it is the output tuple descriptor for
* query : parsetree to be displayed
* the view represented by a SELECT query .
* buf : output text is appended to buf
* parentnamespace : list ( initially empty ) of outer - level deparse_namespace ' s
* resultDesc : if not NULL , the output tuple descriptor for the view
* represented by a SELECT query . We use the column names from it
* to label SELECT output columns , in preference to names in the query
* colNamesVisible : true if the surrounding context cares about the output
* column names at all ( as , for example , an EXISTS ( ) context does not ) ;
* when false , we can suppress dummy column labels such as " ?column? "
* prettyFlags : bitmask of PRETTYFLAG_XXX options
* wrapColumn : maximum line length , or - 1 to disable wrapping
* startIndent : initial indentation amount
* - - - - - - - - - -
* - - - - - - - - - -
*/
*/
static void
static void
get_query_def ( Query * query , StringInfo buf , List * parentnamespace ,
get_query_def ( Query * query , StringInfo buf , List * parentnamespace ,
TupleDesc resultDesc ,
TupleDesc resultDesc , bool colNamesVisible ,
int prettyFlags , int wrapColumn , int startIndent )
int prettyFlags , int wrapColumn , int startIndent )
{
{
deparse_context context ;
deparse_context context ;
@ -5044,19 +5057,19 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
switch ( query - > commandType )
switch ( query - > commandType )
{
{
case CMD_SELECT :
case CMD_SELECT :
get_select_query_def ( query , & context , resultDesc ) ;
get_select_query_def ( query , & context , resultDesc , colNamesVisible ) ;
break ;
break ;
case CMD_UPDATE :
case CMD_UPDATE :
get_update_query_def ( query , & context ) ;
get_update_query_def ( query , & context , colNamesVisible ) ;
break ;
break ;
case CMD_INSERT :
case CMD_INSERT :
get_insert_query_def ( query , & context ) ;
get_insert_query_def ( query , & context , colNamesVisible ) ;
break ;
break ;
case CMD_DELETE :
case CMD_DELETE :
get_delete_query_def ( query , & context ) ;
get_delete_query_def ( query , & context , colNamesVisible ) ;
break ;
break ;
case CMD_NOTHING :
case CMD_NOTHING :
@ -5180,6 +5193,7 @@ get_with_clause(Query *query, deparse_context *context)
if ( PRETTY_INDENT ( context ) )
if ( PRETTY_INDENT ( context ) )
appendContextKeyword ( context , " " , 0 , 0 , 0 ) ;
appendContextKeyword ( context , " " , 0 , 0 , 0 ) ;
get_query_def ( ( Query * ) cte - > ctequery , buf , context - > namespaces , NULL ,
get_query_def ( ( Query * ) cte - > ctequery , buf , context - > namespaces , NULL ,
true ,
context - > prettyFlags , context - > wrapColumn ,
context - > prettyFlags , context - > wrapColumn ,
context - > indentLevel ) ;
context - > indentLevel ) ;
if ( PRETTY_INDENT ( context ) )
if ( PRETTY_INDENT ( context ) )
@ -5203,7 +5217,7 @@ get_with_clause(Query *query, deparse_context *context)
*/
*/
static void
static void
get_select_query_def ( Query * query , deparse_context * context ,
get_select_query_def ( Query * query , deparse_context * context ,
TupleDesc resultDesc )
TupleDesc resultDesc , bool colNamesVisible )
{
{
StringInfo buf = context - > buf ;
StringInfo buf = context - > buf ;
List * save_windowclause ;
List * save_windowclause ;
@ -5227,13 +5241,14 @@ get_select_query_def(Query *query, deparse_context *context,
*/
*/
if ( query - > setOperations )
if ( query - > setOperations )
{
{
get_setop_query ( query - > setOperations , query , context , resultDesc ) ;
get_setop_query ( query - > setOperations , query , context , resultDesc ,
colNamesVisible ) ;
/* ORDER BY clauses must be simple in this case */
/* ORDER BY clauses must be simple in this case */
force_colno = true ;
force_colno = true ;
}
}
else
else
{
{
get_basic_select_query ( query , context , resultDesc ) ;
get_basic_select_query ( query , context , resultDesc , colNamesVisible ) ;
force_colno = false ;
force_colno = false ;
}
}
@ -5403,7 +5418,7 @@ get_simple_values_rte(Query *query, TupleDesc resultDesc)
static void
static void
get_basic_select_query ( Query * query , deparse_context * context ,
get_basic_select_query ( Query * query , deparse_context * context ,
TupleDesc resultDesc )
TupleDesc resultDesc , bool colNamesVisible )
{
{
StringInfo buf = context - > buf ;
StringInfo buf = context - > buf ;
RangeTblEntry * values_rte ;
RangeTblEntry * values_rte ;
@ -5456,7 +5471,7 @@ get_basic_select_query(Query *query, deparse_context *context,
}
}
/* Then we tell what to select (the targetlist) */
/* Then we tell what to select (the targetlist) */
get_target_list ( query - > targetList , context , resultDesc ) ;
get_target_list ( query - > targetList , context , resultDesc , colNamesVisible ) ;
/* Add the FROM clause if needed */
/* Add the FROM clause if needed */
get_from_clause ( query , " FROM " , context ) ;
get_from_clause ( query , " FROM " , context ) ;
@ -5526,11 +5541,13 @@ get_basic_select_query(Query *query, deparse_context *context,
* get_target_list - Parse back a SELECT target list
* get_target_list - Parse back a SELECT target list
*
*
* This is also used for RETURNING lists in INSERT / UPDATE / DELETE .
* This is also used for RETURNING lists in INSERT / UPDATE / DELETE .
*
* resultDesc and colNamesVisible are as for get_query_def ( )
* - - - - - - - - - -
* - - - - - - - - - -
*/
*/
static void
static void
get_target_list ( List * targetList , deparse_context * context ,
get_target_list ( List * targetList , deparse_context * context ,
TupleDesc resultDesc )
TupleDesc resultDesc , bool colNamesVisible )
{
{
StringInfo buf = context - > buf ;
StringInfo buf = context - > buf ;
StringInfoData targetbuf ;
StringInfoData targetbuf ;
@ -5581,8 +5598,13 @@ get_target_list(List *targetList, deparse_context *context,
else
else
{
{
get_rule_expr ( ( Node * ) tle - > expr , context , true ) ;
get_rule_expr ( ( Node * ) tle - > expr , context , true ) ;
/* We'll show the AS name unless it's this: */
attname = " ?column? " ;
/*
* When colNamesVisible is true , we should always show the
* assigned column name explicitly . Otherwise , show it only if
* it ' s not FigureColname ' s fallback .
*/
attname = colNamesVisible ? NULL : " ?column? " ;
}
}
/*
/*
@ -5661,7 +5683,7 @@ get_target_list(List *targetList, deparse_context *context,
static void
static void
get_setop_query ( Node * setOp , Query * query , deparse_context * context ,
get_setop_query ( Node * setOp , Query * query , deparse_context * context ,
TupleDesc resultDesc )
TupleDesc resultDesc , bool colNamesVisible )
{
{
StringInfo buf = context - > buf ;
StringInfo buf = context - > buf ;
bool need_paren ;
bool need_paren ;
@ -5687,6 +5709,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
if ( need_paren )
if ( need_paren )
appendStringInfoChar ( buf , ' ( ' ) ;
appendStringInfoChar ( buf , ' ( ' ) ;
get_query_def ( subquery , buf , context - > namespaces , resultDesc ,
get_query_def ( subquery , buf , context - > namespaces , resultDesc ,
colNamesVisible ,
context - > prettyFlags , context - > wrapColumn ,
context - > prettyFlags , context - > wrapColumn ,
context - > indentLevel ) ;
context - > indentLevel ) ;
if ( need_paren )
if ( need_paren )
@ -5729,7 +5752,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
else
else
subindent = 0 ;
subindent = 0 ;
get_setop_query ( op - > larg , query , context , resultDesc ) ;
get_setop_query ( op - > larg , query , context , resultDesc , colNamesVisible ) ;
if ( need_paren )
if ( need_paren )
appendContextKeyword ( context , " ) " , - subindent , 0 , 0 ) ;
appendContextKeyword ( context , " ) " , - subindent , 0 , 0 ) ;
@ -5773,7 +5796,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
subindent = 0 ;
subindent = 0 ;
appendContextKeyword ( context , " " , subindent , 0 , 0 ) ;
appendContextKeyword ( context , " " , subindent , 0 , 0 ) ;
get_setop_query ( op - > rarg , query , context , resultDesc ) ;
get_setop_query ( op - > rarg , query , context , resultDesc , false ) ;
if ( PRETTY_INDENT ( context ) )
if ( PRETTY_INDENT ( context ) )
context - > indentLevel - = subindent ;
context - > indentLevel - = subindent ;
@ -6108,7 +6131,8 @@ get_rule_windowspec(WindowClause *wc, List *targetList,
* - - - - - - - - - -
* - - - - - - - - - -
*/
*/
static void
static void
get_insert_query_def ( Query * query , deparse_context * context )
get_insert_query_def ( Query * query , deparse_context * context ,
bool colNamesVisible )
{
{
StringInfo buf = context - > buf ;
StringInfo buf = context - > buf ;
RangeTblEntry * select_rte = NULL ;
RangeTblEntry * select_rte = NULL ;
@ -6218,6 +6242,7 @@ get_insert_query_def(Query *query, deparse_context *context)
{
{
/* Add the SELECT */
/* Add the SELECT */
get_query_def ( select_rte - > subquery , buf , NIL , NULL ,
get_query_def ( select_rte - > subquery , buf , NIL , NULL ,
false ,
context - > prettyFlags , context - > wrapColumn ,
context - > prettyFlags , context - > wrapColumn ,
context - > indentLevel ) ;
context - > indentLevel ) ;
}
}
@ -6311,7 +6336,7 @@ get_insert_query_def(Query *query, deparse_context *context)
{
{
appendContextKeyword ( context , " RETURNING " ,
appendContextKeyword ( context , " RETURNING " ,
- PRETTYINDENT_STD , PRETTYINDENT_STD , 1 ) ;
- PRETTYINDENT_STD , PRETTYINDENT_STD , 1 ) ;
get_target_list ( query - > returningList , context , NULL ) ;
get_target_list ( query - > returningList , context , NULL , colNamesVisible ) ;
}
}
}
}
@ -6321,7 +6346,8 @@ get_insert_query_def(Query *query, deparse_context *context)
* - - - - - - - - - -
* - - - - - - - - - -
*/
*/
static void
static void
get_update_query_def ( Query * query , deparse_context * context )
get_update_query_def ( Query * query , deparse_context * context ,
bool colNamesVisible )
{
{
StringInfo buf = context - > buf ;
StringInfo buf = context - > buf ;
RangeTblEntry * rte ;
RangeTblEntry * rte ;
@ -6366,7 +6392,7 @@ get_update_query_def(Query *query, deparse_context *context)
{
{
appendContextKeyword ( context , " RETURNING " ,
appendContextKeyword ( context , " RETURNING " ,
- PRETTYINDENT_STD , PRETTYINDENT_STD , 1 ) ;
- PRETTYINDENT_STD , PRETTYINDENT_STD , 1 ) ;
get_target_list ( query - > returningList , context , NULL ) ;
get_target_list ( query - > returningList , context , NULL , colNamesVisible ) ;
}
}
}
}
@ -6528,7 +6554,8 @@ get_update_query_targetlist_def(Query *query, List *targetList,
* - - - - - - - - - -
* - - - - - - - - - -
*/
*/
static void
static void
get_delete_query_def ( Query * query , deparse_context * context )
get_delete_query_def ( Query * query , deparse_context * context ,
bool colNamesVisible )
{
{
StringInfo buf = context - > buf ;
StringInfo buf = context - > buf ;
RangeTblEntry * rte ;
RangeTblEntry * rte ;
@ -6569,7 +6596,7 @@ get_delete_query_def(Query *query, deparse_context *context)
{
{
appendContextKeyword ( context , " RETURNING " ,
appendContextKeyword ( context , " RETURNING " ,
- PRETTYINDENT_STD , PRETTYINDENT_STD , 1 ) ;
- PRETTYINDENT_STD , PRETTYINDENT_STD , 1 ) ;
get_target_list ( query - > returningList , context , NULL ) ;
get_target_list ( query - > returningList , context , NULL , colNamesVisible ) ;
}
}
}
}
@ -9896,7 +9923,7 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
if ( need_paren )
if ( need_paren )
appendStringInfoChar ( buf , ' ( ' ) ;
appendStringInfoChar ( buf , ' ( ' ) ;
get_query_def ( query , buf , context - > namespaces , NULL ,
get_query_def ( query , buf , context - > namespaces , NULL , false ,
context - > prettyFlags , context - > wrapColumn ,
context - > prettyFlags , context - > wrapColumn ,
context - > indentLevel ) ;
context - > indentLevel ) ;
@ -10142,6 +10169,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
/* Subquery RTE */
/* Subquery RTE */
appendStringInfoChar ( buf , ' ( ' ) ;
appendStringInfoChar ( buf , ' ( ' ) ;
get_query_def ( rte - > subquery , buf , context - > namespaces , NULL ,
get_query_def ( rte - > subquery , buf , context - > namespaces , NULL ,
true ,
context - > prettyFlags , context - > wrapColumn ,
context - > prettyFlags , context - > wrapColumn ,
context - > indentLevel ) ;
context - > indentLevel ) ;
appendStringInfoChar ( buf , ' ) ' ) ;
appendStringInfoChar ( buf , ' ) ' ) ;