Improve error messages for INSERT queries that have subqueries

pull/2038/head
Onder Kalaci 2018-03-05 14:46:47 +02:00
parent e7b28dd469
commit 40b898b59f
4 changed files with 29 additions and 19 deletions

View File

@ -562,27 +562,15 @@ ModifyQuerySupported(Query *queryTree, Query *originalQuery, bool multiShardQuer
*/
if (queryTree->hasSubLinks == true)
{
/*
* We support UPDATE and DELETE with subqueries unless they are multi
* shard queries.
*/
/* we support subqueries for INSERTs only via INSERT INTO ... SELECT */
if (!UpdateOrDeleteQuery(queryTree))
{
StringInfo errorHint = makeStringInfo();
DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(
distributedTableId);
char *partitionKeyString = cacheEntry->partitionKeyString;
char *partitionColumnName = ColumnNameToColumn(distributedTableId,
partitionKeyString);
appendStringInfo(errorHint,
"Consider using an equality filter on partition column \"%s\" to target a single shard.",
partitionColumnName);
Assert(queryTree->commandType == CMD_INSERT);
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"subqueries are not supported in modifications across "
"multiple shards",
errorHint->data, NULL);
"subqueries are not supported within INSERT queries",
NULL, "Try rewriting your queries with 'INSERT "
"INTO ... SELECT' syntax.");
}
}

View File

@ -1275,6 +1275,20 @@ SELECT * FROM summary_table ORDER BY id;
----+-----------+---------------+-------+---------
(0 rows)
-- we don't support subqueries in VALUES clause
INSERT INTO summary_table (id) VALUES ((SELECT id FROM summary_table));
ERROR: subqueries are not supported within INSERT queries
HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax.
INSERT INTO summary_table (id) VALUES (5), ((SELECT id FROM summary_table));
ERROR: subqueries are not supported within INSERT queries
HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax.
-- similar queries with reference tables
INSERT INTO reference_summary_table (id) VALUES ((SELECT id FROM summary_table));
ERROR: subqueries are not supported within INSERT queries
HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax.
INSERT INTO summary_table (id) VALUES ((SELECT id FROM reference_summary_table));
ERROR: subqueries are not supported within INSERT queries
HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax.
DROP TABLE raw_table;
DROP TABLE summary_table;
DROP TABLE reference_raw_table;

View File

@ -253,8 +253,8 @@ INSERT INTO dropcol_distributed AS dropcol (key, keep1) VALUES (1, '5') ON CONFL
-- subquery in the SET clause
INSERT INTO upsert_test (part_key, other_col) VALUES (1, 1) ON CONFLICT (part_key) DO
UPDATE SET other_col = (SELECT count(*) from upsert_test);
ERROR: subqueries are not supported in modifications across multiple shards
DETAIL: Consider using an equality filter on partition column "part_key" to target a single shard.
ERROR: subqueries are not supported within INSERT queries
HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax.
-- non mutable function call in the SET
INSERT INTO upsert_test (part_key, other_col) VALUES (1, 1) ON CONFLICT (part_key) DO
UPDATE SET other_col = random()::int;

View File

@ -821,6 +821,14 @@ EXECUTE prepared_delete_with_join(6);
SELECT * FROM summary_table ORDER BY id;
-- we don't support subqueries in VALUES clause
INSERT INTO summary_table (id) VALUES ((SELECT id FROM summary_table));
INSERT INTO summary_table (id) VALUES (5), ((SELECT id FROM summary_table));
-- similar queries with reference tables
INSERT INTO reference_summary_table (id) VALUES ((SELECT id FROM summary_table));
INSERT INTO summary_table (id) VALUES ((SELECT id FROM reference_summary_table));
DROP TABLE raw_table;
DROP TABLE summary_table;
DROP TABLE reference_raw_table;