@@ -3690,8 +3690,8 @@ get_insert_query_def(Query *query, deparse_context *context)
36903690 get_with_clause (query , context );
36913691
36923692 /*
3693- * If it's an INSERT ... SELECT or VALUES (...), (...), ... there will be
3694- * a single RTE for the SELECT or VALUES.
3693+ * If it's an INSERT ... SELECT or multi-row VALUES, there will be a
3694+ * single RTE for the SELECT or VALUES. Plain VALUES has neither .
36953695 */
36963696 foreach (l , query -> rtable )
36973697 {
@@ -3725,7 +3725,7 @@ get_insert_query_def(Query *query, deparse_context *context)
37253725 context -> indentLevel += PRETTYINDENT_STD ;
37263726 appendStringInfoChar (buf , ' ' );
37273727 }
3728- appendStringInfo (buf , "INSERT INTO %s ( " ,
3728+ appendStringInfo (buf , "INSERT INTO %s " ,
37293729 generate_relation_name (rte -> relid , NIL ));
37303730
37313731 /*
@@ -3742,6 +3742,8 @@ get_insert_query_def(Query *query, deparse_context *context)
37423742 values_cell = NULL ;
37433743 strippedexprs = NIL ;
37443744 sep = "" ;
3745+ if (query -> targetList )
3746+ appendStringInfoChar (buf , '(' );
37453747 foreach (l , query -> targetList )
37463748 {
37473749 TargetEntry * tle = (TargetEntry * ) lfirst (l );
@@ -3778,7 +3780,8 @@ get_insert_query_def(Query *query, deparse_context *context)
37783780 context , true));
37793781 }
37803782 }
3781- appendStringInfo (buf , ") " );
3783+ if (query -> targetList )
3784+ appendStringInfo (buf , ") " );
37823785
37833786 if (select_rte )
37843787 {
@@ -3791,14 +3794,19 @@ get_insert_query_def(Query *query, deparse_context *context)
37913794 /* Add the multi-VALUES expression lists */
37923795 get_values_def (values_rte -> values_lists , context );
37933796 }
3794- else
3797+ else if ( strippedexprs )
37953798 {
37963799 /* Add the single-VALUES expression list */
37973800 appendContextKeyword (context , "VALUES (" ,
37983801 - PRETTYINDENT_STD , PRETTYINDENT_STD , 2 );
37993802 get_rule_expr ((Node * ) strippedexprs , context , false);
38003803 appendStringInfoChar (buf , ')' );
38013804 }
3805+ else
3806+ {
3807+ /* No expressions, so it must be DEFAULT VALUES */
3808+ appendStringInfo (buf , "DEFAULT VALUES" );
3809+ }
38023810
38033811 /* Add RETURNING if present */
38043812 if (query -> returningList )
0 commit comments