Insert query not working as expected in Hive - hive

I'm using below query to insert data in hive.
INSERT INTO TABLE dc_financials_sales (salessourcenbr,
salessourcecountrycode, salesendinginvsalesdate,
itemdeptnbr, basedivcode,
childctrtrackingid, msgreceivedts,
finreportinggroupcode, gateoutuserid,
itemshippedqty, itemshippedqtyuom,
itemupc, outboundchanneltype,
parentctrtrackingid, salespolinenbr,
salesponbr, salesdocid, salesdocumenttype,
totalsalescost, totalsalescostuom,
trailergateoutts, trailernbr,
transportationloadid, saptransactionid,
vnpkqtyineaches, whpkqtyineaches,
whpksellcost, whpksellcostuom,
wmtitemnbr, wmtitemdesc)
VALUES (6086, 'US',
'20191115', 7,
'WM', NULL,
'2019-11-21 09:04:06+0000', 'US',
's0k01wf', 1,
'EA', '28914173184',
'Staplestock', NULL,
NULL, NULL,
'1168337034A', 'CO',
100, 'USD',
'2019-11-15 13:39:38+0000', NULL,
NULL, '20191121090405332000000v7bG3NGSALEUS6086',
1, 1,
100, 'USD',
'570495975', 'DISNEY PRINCESS ROYA');
But, getting error:
Your query has the following error(s):
Error while compiling statement: FAILED:
SemanticException 1:38 '[salessourcenbr, salessourcecountrycode, salesendinginvsalesdate]' in insert schema specification are not found among regular columns of default.dc_financials_sales nor dynamic partition columns.
Error encountered near token 'wmtitemdesc'
Can someone help me to understand why the query is not working in Hive?

Hive does not support specifying ordinary (non-partition) columns in INSERT VALUES statement. See Hive Language Manual:
...Values must be provided for every column in the table. The
standard SQL syntax that allows the user to insert values into only
some columns is not yet supported. To mimic the standard SQL, nulls
can be provided for columns the user does not wish to assign a value to.

Related

How can i insert a specific uuid into h2 database using sql script

I am using a h2 database to run my tests and i need to insert some default values in the database prior to testing. I'm trying to write an sql script for this however, i am having an issue inserting a uuid as a value into the relevant table.
I tried inserting the uuid as follows; insert into user_profile_table (profile_id, user_id) values (1, 'c80d54d3-500d-4539-9479-8e8961477193'); however i get an JdbcSQLDataException error stating: Value too long for column.
I assumed this is because the user_id column type is BINARY(16) so i decided to try the following query insert into user_profile_table (profile_id, userkeycloak_id) values (1, UNHEX(REPLACE('c80d54d3-500d-4539-9479-8e8961477193', '-',''))); however, then i get an error stating: JdbcSQLSyntaxErrorException: Function "UNHEX" not found; SQL statement. I read online that the h2 DB does not support the unhex function. I tried to look for others means of converting the the uuid to a format compatible with the h2 database but havent had any luck finding a viable solution.
Hence, my question is: is there any query i can use to insert the uuid (in a BINARY(16)) format into the h2 db table? Any suggestions would be highly appreciated.
To insert a UUID value into BINARY(16) column you can use standard binary string literals in both MySQL and H2:
insert into user_profile_table (profile_id, user_id)
values (1, X'c80d54d3500d453994798e8961477193');
try this solution by microsoft : https://learn.microsoft.com/en-us/sql/t-sql/data-types/uniqueidentifier-transact-sql?view=sql-server-ver16

Subqueries for PostgreSQL returns syntax error near select

I am a beginner to database, and I am trying to run a subquery to insert data from one table to another one with identical schema.
insert into tbl_technologies_used (t_name_tech, t_category_tech, i_rating)
values (
select t_name_tech, t_category_tech, i_rating
from tbl_technologies_proposed
);
But I got this error:
ERROR: syntax error at or near "select"
LINE 1: ... (t_name_tech, t_category_tech, i_rating) values (select t_n...
How can I fix this issue? I have checked my code again and again, but I can't find out the error.
If the source of an INSERT is a SELECT, you can't use VALUES:
insert into tbl_technologies_used (t_name_tech, t_category_tech, i_rating)
select t_name_tech, t_category_tech, i_rating
from tbl_technologies_proposed
The values clause provides a static set of rows which is not needed as the rows to be inserted come from your SELECT statement.

value too long for type character varying(200) in postgres

I am using the django model for my project When I hit my query to insert the row.I am getting an error
Query:
INSERT INTO "intelligence_centre_organicsearchresults"
("keyword", "location", "position", "page_no", "headline", "url", "exerpt", "query_url", "content_updated_date", "created_on", "modified_on", "downloaded")
VALUES
(E'abilify', NULL, 8, 1, E'NAMI | Abilify (aripiprazole)', E'/url?q=http://www.nami.org/Template.cfm?Section=About_Medications&template=/ContentManagement/ContentDisplay.cfm&ContentID=8133&sa=U&ei=-v5VT7HkHMTsrAf5wqCLBw&ved=0CEEQFjAH&usg=AFQjCNG7-G-LSrWE65DeZuDmy2Uvi71HTg', E'What is the most important information I should know about Abilify®? Relapse is very common in schizophrenia and the most frequent cause is that patients stop ...www.nami.org/Template.cfm?Section=About_Medications... - Cached - Similar', NULL, NULL, E'2012-03-06 06:11:37.606388', E'2012-03-06 06:11:37.606449', true)
Error:
ERROR: value too long for type character varying(200)
My schema field sizes are also extended for this problem:
ALTER TABLE intelligence_centre_adwordsearchresults
ALTER COLUMN landing_page_url TYPE character varying(1000)
likewise I had extended the size for all fields.
i have attached my table description as screen shot.
Please suggest me to solve this error?
You are getting an error inserting into intelligence_centre_ORGANICsearchresults, but you've altered the columns on intelligence_centre_ADWORDsearchresults. I think you need to alter the columns on intelligence_centre_ORGANICsearchresults.
Check the table names first. Your solution is okay if you see the table names.

Why sqlite complains to this code?

I am writing a project and using generation sql for testing, but SQLite explains to my code.
INSERT INTO Categories
(CategoryId, Name, UrlName, CategoryIndex)
VALUES
('b2cc232c-0d5c-4f35-bb6f-29c67d7d40c2', 'Using Forums', 'usingforums', 0),
('ad9b355d-77bf-4a30-b3fe-7d562df2899f', '.NET Development', 'netdevelopment', 1),
('c4882e5e-4eb5-4e5e-b73a-3bf358bda60e', 'Visual Studio', 'visualstudio', 2),
('8c611ec3-5c2c-45c2-be01-6595b43155ee', 'Visual C#', 'visualcsharp', 3),
('c96cea21-de98-4d68-b22b-90eea66d6b77', 'Visual C++', 'visualcpp', 4),
('c6fb52d5-d4c6-48c2-8892-75f9cb330106', 'Architecture', 'architecture', 5),
('20616eb8-2273-449b-8f65-a49621b92ea4', 'SQL Server', 'sqlserver', 6)
Error:
SQL Execution Error.
Executed SQL statement: INSERT INTO Categories...
Error Source: System.Data.SQLite
Error Message: SQLite error
near "," syntax error
Schema of this table:
table Categories (
CategoryId UNIQUEIDENTIFIER not null,
Name TEXT not null,
UrlName TEXT not null,
CategoryIndex INTEGER not null,
primary key (CategoryId)
)
Why?
SQLite doesn't allow you to insert multiple rows with the values clause.
Try a union all select instead:
INSERT INTO Categories
(CategoryId, Name, UrlName, CategoryIndex)
select 'b2cc232c-0d5c-4f35-bb6f-29c67d7d40c2', 'Using Forums', 'usingforums', 0
union all select 'ad9b355d-77bf-4a30-b3fe-7d562df2899f', '.NET Development', 'netdevelopment', 1
....
SQLite doesn't support the multi-values insert syntax - that's a MySQL extension to SQL syntax. You'll have to rewrite this as one-query-per-value-set, so 7 different queries.
Because your SQL is not valid. You can only insert a single tuple of values in each INSERT statement.
I don't think anyone here has answered thew question - 'why does sql lite complain...' because if you look at the sqlite documentation, it DOES allow multiple values on insert: http://www.sqlite.org/lang_insert.html, excerpt:
"The first form (with the "VALUES" keyword) creates one or more new rows in an existing table."
So what is wrong with this code?
INSERT INTO "roles" ("description", "name", "rid") VALUES ('Administrator','admin',2), ('Member','member',3)
gies this error: Query Error: near ",": syntax error Unable to execute statement
but this works:
INSERT INTO "roles" ("description", "name", "rid") VALUES ('Administrator','admin',2)
For future reference SQLite has somewhat recently added a feature which allows for multiple entries per query delimited by commas as in your example. See user2241515s answer for further info and link.
That said, I have tested this. With new versions of SQLite3 it does work ( 3.7.11+ ) from the console, at least in my case. The problem is it will probably take a while for various SQL parsers to catch up. As an example, I am using Qt for this. The same statement that works in console does not work when executed by a Qt application. The error is the same as above:
Database error: near ",": syntax error Unable to execute statement
Another possible issue is that SQLite does not allow for large queries (I think the limit is around 500 created rows per query right now). But the error for that looks different.

Oracle case sensitive Format SQL

I need to format SQL statement for Oracle Db. I have a sql statement and I don't want to change the case. For Eg.
CREATE TABLE DPAuditTrailDetail
(
ID NUMBER (19, 0) DEFAULT 0 NOT NULL,
AuditTrail NUMBER (19, 0) DEFAULT 0 NOT NULL,
sysObjectField NUMBER (19, 0) DEFAULT 0 NOT NULL,
OldValue NCLOB DEFAULT NULL ,
NewValue NCLOB DEFAULT '' NOT NULL,
Referenced NUMBER (19, 0) DEFAULT NULL
);
I believe, to create table with this table name and column names in oracle, i will have to add double quotes("") to each name. I have a big script and I would like to do it as quick as possible.
Please do suggest some quick way to do it.
Thanks.
Just use the CREATE statement as-is. The tables will be created so that all the following will work just fine:
select AuditTrail from DPAuditTrailDetail where ID=1;
select AUDITTRAIL from DPAUDITTRAILDETAIL where ID=1;
select aUdITtraIL from dpaudittraildetaiL where id=1;
Oracle queries are case-insensitive by default and your life (and that of those maintaining your code when you're gone) will be easier if you stick to this default.
If you really have to use case-sensitive table/column names, the only way is to add double-quotes to table/column names. But as the commenters said, it's not good practice to use case-sensitive names