@@ -3196,8 +3196,8 @@ get_insert_query_def(Query *query, deparse_context *context)
3196
3196
List * strippedexprs ;
3197
3197
3198
3198
/*
3199
- * If it's an INSERT ... SELECT orVALUES (...), (...), ... there will be
3200
- *a single RTE for the SELECT or VALUES.
3199
+ * If it's an INSERT ... SELECT ormulti-row VALUES, there will be a
3200
+ * single RTE for the SELECT or VALUES. Plain VALUES has neither .
3201
3201
*/
3202
3202
foreach (l ,query -> rtable )
3203
3203
{
@@ -3231,7 +3231,7 @@ get_insert_query_def(Query *query, deparse_context *context)
3231
3231
context -> indentLevel += PRETTYINDENT_STD ;
3232
3232
appendStringInfoChar (buf ,' ' );
3233
3233
}
3234
- appendStringInfo (buf ,"INSERT INTO %s( " ,
3234
+ appendStringInfo (buf ,"INSERT INTO %s " ,
3235
3235
generate_relation_name (rte -> relid ,NIL ));
3236
3236
3237
3237
/*
@@ -3248,6 +3248,8 @@ get_insert_query_def(Query *query, deparse_context *context)
3248
3248
values_cell = NULL ;
3249
3249
strippedexprs = NIL ;
3250
3250
sep = "" ;
3251
+ if (query -> targetList )
3252
+ appendStringInfoChar (buf ,'(' );
3251
3253
foreach (l ,query -> targetList )
3252
3254
{
3253
3255
TargetEntry * tle = (TargetEntry * )lfirst (l );
@@ -3284,7 +3286,8 @@ get_insert_query_def(Query *query, deparse_context *context)
3284
3286
context , true));
3285
3287
}
3286
3288
}
3287
- appendStringInfo (buf ,") " );
3289
+ if (query -> targetList )
3290
+ appendStringInfo (buf ,") " );
3288
3291
3289
3292
if (select_rte )
3290
3293
{
@@ -3299,7 +3302,7 @@ get_insert_query_def(Query *query, deparse_context *context)
3299
3302
/* Add the multi-VALUES expression lists */
3300
3303
get_values_def (values_rte -> values_lists ,context );
3301
3304
}
3302
- else
3305
+ else if ( strippedexprs )
3303
3306
{
3304
3307
/* A WITH clause is possible here */
3305
3308
get_with_clause (query ,context );
@@ -3309,6 +3312,11 @@ get_insert_query_def(Query *query, deparse_context *context)
3309
3312
get_rule_expr ((Node * )strippedexprs ,context , false);
3310
3313
appendStringInfoChar (buf ,')' );
3311
3314
}
3315
+ else
3316
+ {
3317
+ /* No expressions, so it must be DEFAULT VALUES */
3318
+ appendStringInfo (buf ,"DEFAULT VALUES" );
3319
+ }
3312
3320
3313
3321
/* Add RETURNING if present */
3314
3322
if (query -> returningList )