mirror of https://github.com/citusdata/citus.git
Merge pull request #1085 from citusdata/improve_insert_select_error_messages
Improve error messages for INSERT INTO .. SELECT cr: @jasonmp85pull/1120/head
commit
d6ed47a7e6
|
@ -820,77 +820,211 @@ ErrorIfInsertPartitionColumnDoesNotMatchSelect(Query *query, RangeTblEntry *inse
|
|||
uint32 rangeTableId = 1;
|
||||
Oid insertRelationId = insertRte->relid;
|
||||
Var *insertPartitionColumn = PartitionColumn(insertRelationId, rangeTableId);
|
||||
bool partitionColumnsMatch = false;
|
||||
Query *subquery = subqueryRte->subquery;
|
||||
bool targetTableHasPartitionColumn = false;
|
||||
|
||||
foreach(targetEntryCell, query->targetList)
|
||||
{
|
||||
TargetEntry *targetEntry = (TargetEntry *) lfirst(targetEntryCell);
|
||||
|
||||
if (IsA(targetEntry->expr, Var))
|
||||
{
|
||||
Var *insertVar = (Var *) targetEntry->expr;
|
||||
AttrNumber originalAttrNo = get_attnum(insertRelationId,
|
||||
targetEntry->resname);
|
||||
TargetEntry *subqeryTargetEntry = NULL;
|
||||
Oid originalRelationId = InvalidOid;
|
||||
Var *originalColumn = NULL;
|
||||
List *insertTargetEntryColumnList = pull_var_clause_default((Node *) targetEntry);
|
||||
Var *insertVar = NULL;
|
||||
AttrNumber originalAttrNo = InvalidAttrNumber;
|
||||
TargetEntry *subqueryTargetEntry = NULL;
|
||||
Expr *selectTargetExpr = NULL;
|
||||
Oid subqueryPartitionColumnRelationId = InvalidOid;
|
||||
Var *subqueryPartitionColumn = NULL;
|
||||
List *parentQueryList = NIL;
|
||||
|
||||
/*
|
||||
* We only consider target entries that include a single column. Note that this
|
||||
* is slightly different than directly checking the whether the targetEntry->expr
|
||||
* is a var since the var could be wrapped into an implicit/explicit casting.
|
||||
*
|
||||
* Also note that we skip the target entry if it does not contain a Var, which
|
||||
* corresponds to columns with DEFAULT values on the target list.
|
||||
*/
|
||||
if (list_length(insertTargetEntryColumnList) != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
insertVar = (Var *) linitial(insertTargetEntryColumnList);
|
||||
originalAttrNo = targetEntry->resno;
|
||||
|
||||
/* skip processing of target table non-partition columns */
|
||||
if (originalAttrNo != insertPartitionColumn->varattno)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
subqeryTargetEntry = list_nth(subquery->targetList,
|
||||
insertVar->varattno - 1);
|
||||
/* INSERT query includes the partition column */
|
||||
targetTableHasPartitionColumn = true;
|
||||
|
||||
if (!IsA(subqeryTargetEntry->expr, Var))
|
||||
subqueryTargetEntry = list_nth(subquery->targetList,
|
||||
insertVar->varattno - 1);
|
||||
selectTargetExpr = subqueryTargetEntry->expr;
|
||||
|
||||
parentQueryList = list_make2(query, subquery);
|
||||
FindReferencedTableColumn(selectTargetExpr,
|
||||
parentQueryList, subquery,
|
||||
&subqueryPartitionColumnRelationId,
|
||||
&subqueryPartitionColumn);
|
||||
|
||||
/*
|
||||
* Corresponding (i.e., in the same ordinal position as the target table's
|
||||
* partition column) select target entry does not directly belong a table.
|
||||
* Evaluate its expression type and error out properly.
|
||||
*/
|
||||
if (subqueryPartitionColumnRelationId == InvalidOid)
|
||||
{
|
||||
partitionColumnsMatch = false;
|
||||
char *errorDetailTemplate = "Subquery contains %s in the "
|
||||
"same position as the target table's "
|
||||
"partition column.";
|
||||
|
||||
char *exprDescription = "";
|
||||
|
||||
switch (selectTargetExpr->type)
|
||||
{
|
||||
case T_Const:
|
||||
{
|
||||
exprDescription = "a constant value";
|
||||
break;
|
||||
}
|
||||
|
||||
parentQueryList = list_make2(query, subquery);
|
||||
FindReferencedTableColumn(subqeryTargetEntry->expr,
|
||||
parentQueryList, subquery,
|
||||
&originalRelationId,
|
||||
&originalColumn);
|
||||
|
||||
if (originalRelationId == InvalidOid)
|
||||
case T_OpExpr:
|
||||
{
|
||||
partitionColumnsMatch = false;
|
||||
exprDescription = "an operator";
|
||||
break;
|
||||
}
|
||||
|
||||
case T_FuncExpr:
|
||||
{
|
||||
FuncExpr *subqueryFunctionExpr = (FuncExpr *) selectTargetExpr;
|
||||
|
||||
switch (subqueryFunctionExpr->funcformat)
|
||||
{
|
||||
case COERCE_EXPLICIT_CALL:
|
||||
{
|
||||
exprDescription = "a function call";
|
||||
break;
|
||||
}
|
||||
|
||||
case COERCE_EXPLICIT_CAST:
|
||||
{
|
||||
exprDescription = "an explicit cast";
|
||||
break;
|
||||
}
|
||||
|
||||
case COERCE_IMPLICIT_CAST:
|
||||
{
|
||||
exprDescription = "an implicit cast";
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
exprDescription = "a function call";
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case T_Aggref:
|
||||
{
|
||||
exprDescription = "an aggregation";
|
||||
break;
|
||||
}
|
||||
|
||||
case T_CaseExpr:
|
||||
{
|
||||
exprDescription = "a case expression";
|
||||
break;
|
||||
}
|
||||
|
||||
case T_CoalesceExpr:
|
||||
{
|
||||
exprDescription = "a coalesce expression";
|
||||
break;
|
||||
}
|
||||
|
||||
case T_RowExpr:
|
||||
{
|
||||
exprDescription = "a row expression";
|
||||
break;
|
||||
}
|
||||
|
||||
case T_MinMaxExpr:
|
||||
{
|
||||
exprDescription = "a min/max expression";
|
||||
break;
|
||||
}
|
||||
|
||||
case T_CoerceViaIO:
|
||||
{
|
||||
exprDescription = "an explicit coercion";
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
exprDescription =
|
||||
"an expression that is not a simple column reference";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot plan INSERT INTO ... SELECT "
|
||||
"because partition columns in the target table "
|
||||
"and the subquery do not match"),
|
||||
errdetail(errorDetailTemplate, exprDescription),
|
||||
errhint("Ensure the target table's partition column has a "
|
||||
"corresponding simple column reference to a distributed "
|
||||
"table's partition column in the subquery.")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Reference tables doesn't have a partition column, thus partition columns
|
||||
* cannot match at all.
|
||||
* Insert target expression could only be non-var if the select target
|
||||
* entry does not have the same type (i.e., target column requires casting).
|
||||
*/
|
||||
if (PartitionMethod(originalRelationId) == DISTRIBUTE_BY_NONE)
|
||||
{
|
||||
partitionColumnsMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!IsPartitionColumn(subqeryTargetEntry->expr, subquery))
|
||||
{
|
||||
partitionColumnsMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
partitionColumnsMatch = true;
|
||||
*selectPartitionColumnTableId = originalRelationId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!partitionColumnsMatch)
|
||||
if (!IsA(targetEntry->expr, Var))
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT query should return bare partition column on "
|
||||
"the same ordinal position as the INSERT's partition "
|
||||
"column")));
|
||||
errmsg("cannot plan INSERT INTO ... SELECT "
|
||||
"because partition columns in the target table "
|
||||
"and the subquery do not match"),
|
||||
errdetail(
|
||||
"The data type of the target table's partition column "
|
||||
"should exactly match the data type of the "
|
||||
"corresponding simple column reference in the subquery.")));
|
||||
}
|
||||
|
||||
/* finally, check that the select target column is a partition column */
|
||||
if (!IsPartitionColumn(selectTargetExpr, subquery))
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot plan INSERT INTO ... SELECT "
|
||||
"because partition columns in the target table "
|
||||
"and the subquery do not match"),
|
||||
errdetail(
|
||||
"The target table's partition column "
|
||||
"should correspond to a partition column "
|
||||
"in the subquery.")));
|
||||
}
|
||||
|
||||
/* we can set the select relation id */
|
||||
*selectPartitionColumnTableId = subqueryPartitionColumnRelationId;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!targetTableHasPartitionColumn)
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot plan INSERT INTO ... SELECT "
|
||||
"because the query doesn't include the target table's "
|
||||
"partition column")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -905,7 +1039,7 @@ ErrorIfInsertPartitionColumnDoesNotMatchSelect(Query *query, RangeTblEntry *inse
|
|||
* (i) Set operations are present on the top level query
|
||||
* (ii) Target list does not include a bare partition column.
|
||||
*
|
||||
* Note that if the input query is not an INSERT .. SELECT the assertion fails. Lastly,
|
||||
* Note that if the input query is not an INSERT ... SELECT the assertion fails. Lastly,
|
||||
* if all the participating tables in the query are reference tables, we implicitly
|
||||
* skip adding the quals to the query since IsPartitionColumnRecursive() always returns
|
||||
* false for reference tables.
|
||||
|
@ -2552,7 +2686,8 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
IsA(oldInsertTargetEntry->expr, FieldStore))
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("cannot plan distributed INSERT INTO .. SELECT query"),
|
||||
errmsg(
|
||||
"cannot plan distributed INSERT INTO ... SELECT query"),
|
||||
errhint("Do not use array references and field stores "
|
||||
"on the INSERT target list.")));
|
||||
}
|
||||
|
|
|
@ -1112,7 +1112,8 @@ INSERT INTO agg_events
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The target table's partition column should correspond to a partition column in the subquery.
|
||||
-- We do support some CTEs
|
||||
INSERT INTO agg_events
|
||||
WITH sub_cte AS (SELECT 1)
|
||||
|
@ -1218,7 +1219,8 @@ FROM (SELECT SUM(raw_events_second.value_4) AS v4,
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The data type of the target table's partition column should exactly match the data type of the corresponding simple column reference in the subquery.
|
||||
-- error cases
|
||||
-- no part column at all
|
||||
INSERT INTO raw_events_second
|
||||
|
@ -1228,7 +1230,7 @@ FROM raw_events_first;
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because the query doesn't include the target table's partition column
|
||||
INSERT INTO raw_events_second
|
||||
(value_1)
|
||||
SELECT user_id
|
||||
|
@ -1236,7 +1238,7 @@ FROM raw_events_first;
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because the query doesn't include the target table's partition column
|
||||
INSERT INTO raw_events_second
|
||||
(user_id)
|
||||
SELECT value_1
|
||||
|
@ -1244,7 +1246,8 @@ FROM raw_events_first;
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The target table's partition column should correspond to a partition column in the subquery.
|
||||
INSERT INTO raw_events_second
|
||||
(user_id)
|
||||
SELECT user_id * 2
|
||||
|
@ -1252,7 +1255,9 @@ FROM raw_events_first;
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an operator in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO raw_events_second
|
||||
(user_id)
|
||||
SELECT user_id :: bigint
|
||||
|
@ -1260,7 +1265,9 @@ FROM raw_events_first;
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an explicit cast in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO agg_events
|
||||
(value_3_agg,
|
||||
value_4_agg,
|
||||
|
@ -1277,7 +1284,9 @@ GROUP BY user_id;
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an aggregation in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO agg_events
|
||||
(value_3_agg,
|
||||
value_4_agg,
|
||||
|
@ -1295,7 +1304,8 @@ GROUP BY user_id,
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The target table's partition column should correspond to a partition column in the subquery.
|
||||
-- tables should be co-located
|
||||
INSERT INTO agg_events (user_id)
|
||||
SELECT
|
||||
|
@ -1305,7 +1315,8 @@ FROM
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The target table's partition column should correspond to a partition column in the subquery.
|
||||
-- unsupported joins between subqueries
|
||||
-- we do not return bare partition column on the inner query
|
||||
INSERT INTO agg_events
|
||||
|
@ -1333,7 +1344,9 @@ ON (f.id = f2.id);
|
|||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an expression that is not a simple column reference in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
-- the second part of the query is not routable since
|
||||
-- no GROUP BY on the partition column
|
||||
INSERT INTO agg_events
|
||||
|
@ -1994,6 +2007,74 @@ GROUP BY
|
|||
store_id;
|
||||
ERROR: cannot perform distributed planning for the given modification
|
||||
DETAIL: Volatile functions are not allowed in INSERT ... SELECT queries
|
||||
-- do some more error/error message checks
|
||||
SET citus.shard_count TO 4;
|
||||
SET citus.shard_replication_factor TO 1;
|
||||
CREATE TABLE text_table (part_col text, val int);
|
||||
CREATE TABLE char_table (part_col char[], val int);
|
||||
create table table_with_starts_with_defaults (a int DEFAULT 5, b int, c int);
|
||||
SELECT create_distributed_table('text_table', 'part_col');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT create_distributed_table('char_table','part_col');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT create_distributed_table('table_with_starts_with_defaults', 'c');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
INSERT INTO text_table (part_col)
|
||||
SELECT
|
||||
CASE WHEN part_col = 'onder' THEN 'marco'
|
||||
END
|
||||
FROM text_table ;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains a case expression in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT COALESCE(part_col, 'onder') FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains a coalesce expression in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT GREATEST(part_col, 'jason') FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains a min/max expression in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT LEAST(part_col, 'andres') FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains a min/max expression in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT NULLIF(part_col, 'metin') FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an expression that is not a simple column reference in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT part_col isnull FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an expression that is not a simple column reference in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT part_col::text from char_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an explicit coercion in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT (part_col = 'burak') is true FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an expression that is not a simple column reference in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT val FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The data type of the target table's partition column should exactly match the data type of the corresponding simple column reference in the subquery.
|
||||
INSERT INTO text_table (part_col) SELECT val::text FROM text_table;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: Subquery contains an explicit coercion in the same position as the target table's partition column.
|
||||
HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery.
|
||||
insert into table_with_starts_with_defaults (b,c) select b,c FROM table_with_starts_with_defaults;
|
||||
DROP TABLE raw_events_first CASCADE;
|
||||
NOTICE: drop cascades to view test_view
|
||||
DROP TABLE raw_events_second;
|
||||
|
@ -2001,3 +2082,6 @@ DROP TABLE reference_table;
|
|||
DROP TABLE agg_events;
|
||||
DROP TABLE table_with_defaults;
|
||||
DROP TABLE table_with_serial;
|
||||
DROP TABLE text_table;
|
||||
DROP TABLE char_table;
|
||||
DROP TABLE table_with_starts_with_defaults;
|
||||
|
|
|
@ -1135,7 +1135,8 @@ RETURNING value_1, value_2;
|
|||
2 | 2
|
||||
(2 rows)
|
||||
|
||||
-- partition column value comes from reference table which should error out
|
||||
-- partition column value comes from reference table but still first error is
|
||||
-- on data type mismatch
|
||||
INSERT INTO
|
||||
colocated_table_test (value_1, value_2)
|
||||
SELECT
|
||||
|
@ -1145,7 +1146,20 @@ FROM
|
|||
WHERE
|
||||
colocated_table_test_2.value_4 = reference_table_test.value_4
|
||||
RETURNING value_1, value_2;
|
||||
ERROR: SELECT query should return bare partition column on the same ordinal position as the INSERT's partition column
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The data type of the target table's partition column should exactly match the data type of the corresponding simple column reference in the subquery.
|
||||
-- partition column value comes from reference table which should error out
|
||||
INSERT INTO
|
||||
colocated_table_test (value_1, value_2)
|
||||
SELECT
|
||||
reference_table_test.value_1, colocated_table_test_2.value_1
|
||||
FROM
|
||||
colocated_table_test_2, reference_table_test
|
||||
WHERE
|
||||
colocated_table_test_2.value_4 = reference_table_test.value_4
|
||||
RETURNING value_1, value_2;
|
||||
ERROR: cannot plan INSERT INTO ... SELECT because partition columns in the target table and the subquery do not match
|
||||
DETAIL: The target table's partition column should correspond to a partition column in the subquery.
|
||||
-- some tests for mark_tables_colocated
|
||||
-- should error out
|
||||
SELECT mark_tables_colocated('colocated_table_test_2', ARRAY['reference_table_test']);
|
||||
|
|
|
@ -945,9 +945,41 @@ FROM
|
|||
GROUP BY
|
||||
store_id;
|
||||
|
||||
-- do some more error/error message checks
|
||||
SET citus.shard_count TO 4;
|
||||
SET citus.shard_replication_factor TO 1;
|
||||
CREATE TABLE text_table (part_col text, val int);
|
||||
CREATE TABLE char_table (part_col char[], val int);
|
||||
create table table_with_starts_with_defaults (a int DEFAULT 5, b int, c int);
|
||||
SELECT create_distributed_table('text_table', 'part_col');
|
||||
SELECT create_distributed_table('char_table','part_col');
|
||||
SELECT create_distributed_table('table_with_starts_with_defaults', 'c');
|
||||
|
||||
INSERT INTO text_table (part_col)
|
||||
SELECT
|
||||
CASE WHEN part_col = 'onder' THEN 'marco'
|
||||
END
|
||||
FROM text_table ;
|
||||
|
||||
|
||||
|
||||
INSERT INTO text_table (part_col) SELECT COALESCE(part_col, 'onder') FROM text_table;
|
||||
INSERT INTO text_table (part_col) SELECT GREATEST(part_col, 'jason') FROM text_table;
|
||||
INSERT INTO text_table (part_col) SELECT LEAST(part_col, 'andres') FROM text_table;
|
||||
INSERT INTO text_table (part_col) SELECT NULLIF(part_col, 'metin') FROM text_table;
|
||||
INSERT INTO text_table (part_col) SELECT part_col isnull FROM text_table;
|
||||
INSERT INTO text_table (part_col) SELECT part_col::text from char_table;
|
||||
INSERT INTO text_table (part_col) SELECT (part_col = 'burak') is true FROM text_table;
|
||||
INSERT INTO text_table (part_col) SELECT val FROM text_table;
|
||||
INSERT INTO text_table (part_col) SELECT val::text FROM text_table;
|
||||
insert into table_with_starts_with_defaults (b,c) select b,c FROM table_with_starts_with_defaults;
|
||||
|
||||
DROP TABLE raw_events_first CASCADE;
|
||||
DROP TABLE raw_events_second;
|
||||
DROP TABLE reference_table;
|
||||
DROP TABLE agg_events;
|
||||
DROP TABLE table_with_defaults;
|
||||
DROP TABLE table_with_serial;
|
||||
DROP TABLE text_table;
|
||||
DROP TABLE char_table;
|
||||
DROP TABLE table_with_starts_with_defaults;
|
||||
|
|
|
@ -721,7 +721,8 @@ WHERE
|
|||
colocated_table_test_2.value_2 = reference_table_test.value_2
|
||||
RETURNING value_1, value_2;
|
||||
|
||||
-- partition column value comes from reference table which should error out
|
||||
-- partition column value comes from reference table but still first error is
|
||||
-- on data type mismatch
|
||||
INSERT INTO
|
||||
colocated_table_test (value_1, value_2)
|
||||
SELECT
|
||||
|
@ -732,6 +733,18 @@ WHERE
|
|||
colocated_table_test_2.value_4 = reference_table_test.value_4
|
||||
RETURNING value_1, value_2;
|
||||
|
||||
-- partition column value comes from reference table which should error out
|
||||
INSERT INTO
|
||||
colocated_table_test (value_1, value_2)
|
||||
SELECT
|
||||
reference_table_test.value_1, colocated_table_test_2.value_1
|
||||
FROM
|
||||
colocated_table_test_2, reference_table_test
|
||||
WHERE
|
||||
colocated_table_test_2.value_4 = reference_table_test.value_4
|
||||
RETURNING value_1, value_2;
|
||||
|
||||
|
||||
-- some tests for mark_tables_colocated
|
||||
-- should error out
|
||||
SELECT mark_tables_colocated('colocated_table_test_2', ARRAY['reference_table_test']);
|
||||
|
|
Loading…
Reference in New Issue