@@ -3506,8 +3506,8 @@ get_insert_query_def(Query *query, deparse_context *context)
3506
3506
get_with_clause (query , context );
3507
3507
3508
3508
/*
3509
- * If it's an INSERT ... SELECT or VALUES (...), (...), ... there will be
3510
- * a single RTE for the SELECT or VALUES.
3509
+ * If it's an INSERT ... SELECT or multi-row VALUES, there will be a
3510
+ * single RTE for the SELECT or VALUES. Plain VALUES has neither .
3511
3511
*/
3512
3512
foreach (l , query -> rtable )
3513
3513
{
@@ -3541,7 +3541,7 @@ get_insert_query_def(Query *query, deparse_context *context)
3541
3541
context -> indentLevel += PRETTYINDENT_STD ;
3542
3542
appendStringInfoChar (buf , ' ' );
3543
3543
}
3544
- appendStringInfo (buf , "INSERT INTO %s ( " ,
3544
+ appendStringInfo (buf , "INSERT INTO %s " ,
3545
3545
generate_relation_name (rte -> relid , NIL ));
3546
3546
3547
3547
/*
@@ -3558,6 +3558,8 @@ get_insert_query_def(Query *query, deparse_context *context)
3558
3558
values_cell = NULL ;
3559
3559
strippedexprs = NIL ;
3560
3560
sep = "" ;
3561
+ if (query -> targetList )
3562
+ appendStringInfoChar (buf , '(' );
3561
3563
foreach (l , query -> targetList )
3562
3564
{
3563
3565
TargetEntry * tle = (TargetEntry * ) lfirst (l );
@@ -3594,7 +3596,8 @@ get_insert_query_def(Query *query, deparse_context *context)
3594
3596
context , true));
3595
3597
}
3596
3598
}
3597
- appendStringInfo (buf , ") " );
3599
+ if (query -> targetList )
3600
+ appendStringInfo (buf , ") " );
3598
3601
3599
3602
if (select_rte )
3600
3603
{
@@ -3607,14 +3610,19 @@ get_insert_query_def(Query *query, deparse_context *context)
3607
3610
/* Add the multi-VALUES expression lists */
3608
3611
get_values_def (values_rte -> values_lists , context );
3609
3612
}
3610
- else
3613
+ else if ( strippedexprs )
3611
3614
{
3612
3615
/* Add the single-VALUES expression list */
3613
3616
appendContextKeyword (context , "VALUES (" ,
3614
3617
- PRETTYINDENT_STD , PRETTYINDENT_STD , 2 );
3615
3618
get_rule_expr ((Node * ) strippedexprs , context , false);
3616
3619
appendStringInfoChar (buf , ')' );
3617
3620
}
3621
+ else
3622
+ {
3623
+ /* No expressions, so it must be DEFAULT VALUES */
3624
+ appendStringInfo (buf , "DEFAULT VALUES" );
3625
+ }
3618
3626
3619
3627
/* Add RETURNING if present */
3620
3628
if (query -> returningList )
0 commit comments