SemanticException when inserting: Expression of type tok_table_or_col not supported in insert/values - hive

I want to insert a row into a Hive table as follows:
INSERT INTO TABLE prod_trench_m.bi_batch_control PARTITION (table_name='FinCoa_DM_Party_Income_spendings') VALUES (20221027, 'BDP', Fink_Party_Income_Spendings, -999, 20221031999999, 20221031999999, 'Y', 'I', 'S', 'FinCoa_DM_Party_Income_Spendings');
which raises:
FAILED SemanticException: Unable to create temp file for insert values
Expression of type tok_table_or_col not supported in insert/values
Help/Hints would be appreciated.

Related

syntax error when trying to input date and time

I just started with SQL and I'm having a problem when trying to insert an date and time.
The table structure:
CREATE TABLE Voo_Pac
(
codReserva INT NOT NULL PRIMARY KEY,
DataCont DATE,
HoraCont TIME
);
Code I'm trying to use to insert date and time:
INSERT INTO Voo_Pac (codReserva, DataCont, HoraCont)
VALUES (1), (15-08-2019), (12:13:52);
When I try to execute the code, it gives me the following message:
Error 1: could not prepare statement (1 near ":13": syntax error)
I assume you are using MySQL/MariaDB/SQL Server because of the TIME datatype?
Your insert should be
INSERT INTO Voo_Pac (codReserva, DataCont, HoraCont)
VALUES (1, '2019-08-15', '12:13:52');
see demo
You at least need quotes. And depending on your DB maybe a CAST to the apropiated type
INSERT INTO Voo_Pac (codReserva, DataCont, HoraCont)
VALUES 1, '15-08-2019', '12:13:52';

Getting Error 10293 while inserting a row to a hive table having array as one of the fileds

I have a hive table created using the following query:
create table arraytbl (id string, model string, cost int, colors array <string>,size array <float>)
row format delimited fields terminated by ',' collection items terminated by '#';
Now , while trying to insert a row:
insert into mobilephones values
("AA","AAA",5600,colors("red","blue","green"),size(5.6,4.3));
I get the following error:
FAILED: SemanticException [Error 10293]: Unable to create temp file for insert values Expression of type TOK_FUNCTION not supported in insert/values
How can I resolve this issue?
The syantax to enter values in complex datatype if kinda bit weird, however this is my personal opinion.
You need a dummy table to insert values into hive table with complex datatype.
insert into arraytbl select "AA","AAA",5600, array("red","blue","green"), array(CAST(5.6 AS FLOAT),CAST(4.3 AS FLOAT)) from (select 'a') x;
And this is how it looks after insert.
hive> select * from arraytbl;
OK
AA AAA 5600 ["red","blue","green"] [5.6,4.3]

Postgres insert into a table

I have a SQL script like this which I run from the command line using psql:
insert into "A"."B" values
(1, 'name=a', 'a#example.com', 'K')
How do I convert it into INSERT command inside a database?
INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
Also what does "A"."B" do? I read somewhere that double quotes are needed when table name has Capitals. I seem to get an error with that when I run commands inside the database.
You said that your database name was DB and your table name was B.
You can simply use the table name alone:
INSERT INTO "B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
If you want to include the database name, then use:
INSERT INTO "DB"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
The double quotes are only required when the name of any entity (e.g. table, column, etc...) is a reserved word.
You can use this query where A is schema and B is table name.
INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');

SQLITE_RANGE: bind or column out of range for INSERT statement

I want to insert rows into a SQLite3 table using the knex.raw method. Unfortunately I get a 'SQLITE_RANGE' error, which makes my test fail.
I have verified the bindings passed to the raw query in the following fashion:
They respect the order of the INSERT statement
They respect the specified column types
They respect the number of bindings requested in the raw query
Beyond that I have looked online, but couldn't find a solution to my issue. Below are the details of the operation attempted:
Engine: sqlite3 ^3.1.13
SQL Client: knex ^0.14.4
Environment: electron ^1.7.11
Error:
SQLITE_RANGE: bind or column index out of range errno: 25, code: 'SQLITE_RANGE'
Table definition:
-- --------------------------------------------------------
--
-- Table structure for table `ds13odba`
--
CREATE TABLE IF NOT EXISTS `ds13odba` (
`SURGERY_CODE` VARCHAR(6) ,
`TYPE` VARCHAR(1) ,
`FP59STALIB` VARCHAR(6) ,
`ID` INT UNSIGNED NOT NULL ,
`createdAt` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updatedAt` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
);
-- --------------------------------------------------------
*Take note that the column types defined here are affinity types, i.e. MySQL types. These are valid in SQLite3 and are casted and optimized by the engine to their equivalent in SQLite3.
Query:
INSERT INTO `ds13odba` (FP59STALIB, ID, SURGERY_CODE, TYPE) VALUES (?,?,?,?);
INSERT INTO `ds13odba` (FP59STALIB, ID, SURGERY_CODE, TYPE) VALUES (?,?,?,?);
INSERT INTO `ds13odba` (FP59STALIB, ID, SURGERY_CODE, TYPE) VALUES (?,?,?,?);
Bindings:
[
'047202', 1, '000001', 'D',
'047203', 2, '000002', 'D',
'047204', 3, '000003', 'D'
]
Calling code:
await knex.raw(...convertToInsertSQL(records));
Which resolves to:
await knex.raw(insertStatements.join('\n'), bindings);
Could you help me with this issue?
Cheers 🦋
The issue stems from SQLite3's lack of support of multi-statements per exec() call, as documented here.
After some testing on my end, I discovered that the SQLite3 engine will assign automatically all the bindings to the first statement of the prepared SQL. Any following statements will be ignored.
This still applies for transactions, as the bindings will be applied to the 'BEGIN TRANSACTION;' statement rather than to the following statements.
The solution is to use a compound INSERT statement with bindings.
Hence this:
INSERT INTO `ds13odba` (FP59STALIB, ID, SURGERY_CODE, TYPE) VALUES (?,?,?,?);
INSERT INTO `ds13odba` (FP59STALIB, ID, SURGERY_CODE, TYPE) VALUES (?,?,?,?);
INSERT INTO `ds13odba` (FP59STALIB, ID, SURGERY_CODE, TYPE) VALUES (?,?,?,?);
becomes this:
INSERT INTO `ds13odba` (FP59STALIB, ID, SURGERY_CODE, TYPE)
VALUES (?,?,?,?), (?,?,?,?), (?,?,?,?);
*Bear in mind that compound INSERT statements are only available as of version 3.7.11 of the SQLite3 engine.
I don't see anything obviously wrong with the info you've posted, but you haven't posted the actual .raw() statements, which would help with debugging.
So attempting to assist, I would suggest that you add an .on('query-error'... clause like that below, which will log the SQL that is failing. Many times this will make the problem obvious.
knex.raw(...your-stuff...)
.on('query-error', function(ex, obj) {
console.log("KNEX-query-error ex:", ex, "obj:", obj);
})
Good luck!

Subquery cannot appear in an Insert Values statement

I have the following query in SQL Server CE which gives me an error during the execution time:
INSERT INTO trans_rel(trans, sale_purch_id, inc_exp_id)
VALUES('p', 104, (select MAX(expence_id) from c_expence))
The error is this:
Subquery cannot appear in an Insert Values statement.
What is wrong with this query?
Try this one:
INSERT INTO trans_rel
SELECT 'p', '102', MAX(expence_id)
FROM c_expence
This is exactly what your are looking for:
INSERT INTO trans_rel(trans, sale_purch_id, inc_exp_id)
SELECT 'p' as 'trans', '104' as 'sale_purch_id', MAX(expence_id) AS inc_exp_id
FROM c_expence;