When trying to create a distributed table with Citus, it gives a PG::UndefinedColumn: ERROR: column "x" does not exist
I have enabled Citus on workers and main DB:
SELECT run_command_on_workers($cmd$
CREATE EXTENSION citus;
$cmd$);
I created a composite primary key:
ActiveRecord::Base.connection.execute("
ALTER TABLE x DROP CONSTRAINT x_pkey CASCADE;
")
ActiveRecord::Base.connection.execute("
ALTER TABLE x ADD PRIMARY KEY (tenant_id, id);
")
When trying to do:
ActiveRecord::Base.connection.execute("
SELECT create_distributed_table(x, tenant_id);
")
It keeps saying:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "x" does not exist
LINE 2: SELECT create_distributed_table(x, tenant_id...
^
Caused by PG::UndefinedColumn: ERROR: column "x" does not exist
Is there something I am forgetting?
The table name and column name need to be passed as text values in single quotes: SELECT create_distributed_table('x', 'tenant_id');
Related
There is a Hive-table with 2 string columns one partition "cmd_out".
I'm trying to rename all 2 columns ('col1', 'col2'), by using Replace-function:
Alter table 'table_test' replace columns(
'col22' String,
'coll33' String
)
But I receive the following exception:
Partition column name 'cmd_out' conflicts with table columns.
When I include the partition column in query
Alter table 'table_test' replace columns(
'cmd_out' String,
'col22' String,
'coll33' String
)
I receive:
Duplicate column name cmd_out in the table definition
if you want to rename a column, you need to use alter table ... change.
Here is the syntax
alter table mytab change col1 new_col1 string;
I was looking for way to add column in Hive table via Beeline interface only when its not present.
create table employee(ename string , eid string);
alter table employee add columns (eid string);
Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Duplicate column name: eid (state=08S01,code=1)
is there any way to ignore error or not try adding a column if already present ?
Thanks
Shashi
I'm using Hive 2.1.1 and I'm attempting to create a table with . in a column name:
CREATE TABLE `test_table`(
`field.with.dots` string
);
When I do so I get:
FAILED: ParseException line 4:0 Failed to recognize predicate ')'. Failed rule: '[., :] can not be used in column name in create table statement.' in column specification
I must be doing something wrong because the hive documentation says:
In Hive release 0.13.0 and later, by default column names can be specified within backticks (`) and contain any Unicode character (HIVE-6013)
. is a unicode character. And idea what I might be doing?
To give you more context this is on an Amazon EMR 5.5.0 cluster. Thanks!
Source code: HiveParser
...
private char [] excludedCharForColumnName = {'.', ':'};
...
private CommonTree throwColumnNameException() throws RecognitionException {
throw new FailedPredicateException(input, Arrays.toString(excludedCharForColumnName) + " can not be used in column name in create table statement.", "");
}
Jira ticket :Disallow create table with dot/colon in column name
Please note the motivation:
Since we don't allow users to query column names with dot in the
middle such as emp.no, don't allow users to create tables with such
columns that cannot be queried
It seems create table was handled, but not CTAS nor ALTER TABLE...
hive> create table t as select 1 as `a.b.c`;
OK
hive> desc t;
OK
col_name data_type comment
a.b.c int
Time taken: 0.441 seconds, Fetched: 1 row(s)
hive> select * from t;
FAILED: RuntimeException java.lang.RuntimeException: cannot find field a from [0:a.b.c]
hive> create table t (i int);
OK
hive> alter table t change column i `a.b.c` int
hive> select * from t;
Error while compiling statement: FAILED: RuntimeException java.lang.RuntimeException: cannot find field a from [0:a.b.c]
P.s.
I have updated the documentation (look for colon)
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL
I am working on an Advantage Database Server 8.1 and I have created a new table. I want to add a unique constraint for the combination of 2 columns.
I tried
ALTER TABLE TableName
ADD CONSTRAINT ConstraintName
UNIQUE (ColumnName1, ColumnName2)
but I get the error
"ERROR IN SCRIPT: poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [Extended Systems][Advantage SQL Engine]Expected lexical element not found: You are missing the column names. -- Location of error in the SQL
statement is: 33 (line: 2 column: 5)"
Ok the solution I found is:
CREATE UNIQUE INDEX ConstraintName ON TableName (ColumnName1, ColumnName2);
I am trying to do 2 alters to a column in DB2 in the same alter command, and it doesn't seem to like my syntax. Is there a way to do this? If so, how?
create table tbl(col varchar(10))
The following works, using 2 alter statements:
alter table tbl
alter column col set data type varchar(128)
alter table tbl
alter column col set default current user
The following attempts fail:
alter table tbl
alter column col set data type varchar(128) set default current user
An unexpected token "set data type varchar(128)" was found following
"TBL alter column col". Expected tokens may include: ""..
SQLCODE=-104, SQLSTATE=42601, DRIVER=3.67.28
alter table tbl
alter column col set data type varchar(128) with default current user
An unexpected token "data type varchar(128)" was found following
"alter column col set". Expected tokens may include: ""..
SQLCODE=-104, SQLSTATE=42601, DRIVER=3.67.28
alter table tbl
alter column col set data type varchar(128)
alter column col set default current user
"COL" is a duplicate name.. SQLCODE=-612, SQLSTATE=42711,
DRIVER=3.67.28
You cannot alter the same column twice in the same statement -- that's what SQLCODE -612 is telling you. As per http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.messages.sql.doc/doc/msql00612n.html
a column name can only be referenced in one ADD, DROP COLUMN, or ALTER COLUMN clause in a single ALTER TABLE statement.
The other attempts are syntactically incorrect.
alter table tbl
alter COLUMN col set DATA TYPE VARCHAR(128)
ALTER column B SET DEFAULT current user;