HSQLDB ON DUPLICATE KEY UPDATE syntax error - insert

I try to execute following query:
SET DATABASE SQL SYNTAX MYS TRUE;
and then:
INSERT INTO mytable (id, age) VALUES (1, 1)
ON DUPLICATE KEY UPDATE id=2, age=33;
I get error:
INSERT INTO mytable (id, age) VALUES (1, 1)
ON DUPLICATE KEY
[2020-10-23 11:09:42] [42590][-5590] unexpected end of statement: required: UPDATE : line: 2
What do I wrong ?

The OP reports this in a comment:
PUBLIC.PUBLIC> SET DATABASE SQL SYNTAX MYS TRUE [2020-10-23 11:23:14] completed in 4 ms
PUBLIC.PUBLIC> INSERT INTO tblUserMetadata (userMetadataId, portalId) VALUES (1, 1) ON DUPLICATE KEY [2020-10-23 11:23:14] [42590][-5590] unexpected end of statement: required: UPDATE : line: 2
The lines show an SQL client is being used to run a script. The SQL client pre-parses the statement and thinks the statement is finished after the keyword KEY, and the keyword UPDATE is the start of a new statement. So it tries to send the incomplete SQL query to the database engine.
The MySQL syntax is in operation because the command was accepted and executed.
You can check the property settings by selecting from a system table:
SELECT * FROM information_schema.system_properties
The statement below returns true when the MySQL compatibility mode has been set:
SELECT property_value FROM information_schema.system_properties
WHERE property_name = 'sql.syntax_mys'

Related

EFCore error:- ORA-00904: "m"."Id": invalid identifier

I am working with an application using asp.net core 2.2 and efcore database first approach with Oracle database. I am using Oracle.EntityFrameworkCore (2.19.60) nuget package, successfully mapped db model, but when I try to fetch data from DBContext , getting error
ORA-00904: "m"."Id": invalid identifier
Oracle Database version: Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production
code:
var fetched = await myDatabaseContext.MyTableVersions.ToListAsync();
LinQ is generating following query :
SELECT "m"."Id", "m"."MAJORVERSION" FROM "MyTableVersions" "m"
Since It's not a correct syntax for PL/Sql query so getting error ORA-00904: "m"."Id": invalid identifier.
Is there any way to fix this error? Thanks.
I have searched on the web and found
Bug 30352492 - EFCORE: ORA-00904: INVALID IDENTIFIER
but that issue is related to schema.
The query is perfectly valid (db<>fiddle here), assuming your table looks something like
CREATE TABLE "MyTableVersions"
("Id" NUMBER,
MAJORVERSION NUMBER)
However, I suspect your table looks like
CREATE TABLE "MyTableVersions"
(ID NUMBER,
MAJORVERSION NUMBER)
I don't know what the class looks like that you're trying to fetch into, but I suspect it has a field named Id. If you can change the name of that field to ID (in other words, so that its capitalization matches the capitalization of the related database column) you might find it works then.
Double quotes are something you should avoid in Oracle world.
Your query:
SELECT "m"."Id", "m"."MAJORVERSION" FROM "MyTableVersions" "m"
means that column name is exactly Id (capital I followed by d). Only if that's really so, you should use double quotes. Otherwise, simply remove them:
SELECT m.id, m.MAJORVERSION FROM MyTableVersions m
The same goes for the table name - if it was created using mixed case (and you can't do that without double quotes), you'll have to use double quotes and exactly same letter case always. Otherwise, don't use them.
Oracle is case-insensitive regarding object and column names and are UPPERCASE by default:
SQL> create table test (id number);
Table created.
SQL> desc test
Name Null? Type
----------------------------------------- -------- -----------------
ID NUMBER
SQL> select table_name, column_name
2 from user_tab_columns
3 where table_name = 'TEST';
TABLE_NAME COLUMN_NAME
------------------------------ ------------------------------
TEST ID
SQL> insert into test (id) values (1);
1 row created.
SQL>
But, if you use mixed case with double quotes, then use them always:
SQL> create table "teST" ("Id" number);
Table created.
SQL> insert into test (id) values (1);
insert into test (id) values (1)
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> insert into "test" (id) values (1);
insert into "test" (id) values (1)
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> insert into "teST" (id) values (1);
insert into "teST" (id) values (1)
*
ERROR at line 1:
ORA-00904: "ID": invalid identifier
SQL> insert into "teST" ("Id") values (1);
1 row created.
SQL>
So: first make sure what table and column names really are, then use them appropriately.
To avoid problems with case-sensitivity, add the option to eliminate EF to add quotes to the generated queries. For instance, if you are using Devart Oracle provider, this is done in the following way:
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpDbContextOptions>(options =>
{
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.Workarounds.DisableQuoting = true;
...
}
}
If you are using official provider - just inherit from DbCommandInterceptor (do quotes replacement with empty character in dbCommand in ...Executing methods), add this interceptor to DbContextOptionsBuilder instance.

SQL Trigger error (ORA-00942: table or view does not exist)

I create this sql trigger:
CREATE OR REPLACE TRIGGER create_event_from_task BEFORE INSERT ON llx_projet_task
BEGIN
INSERT INTO llx_actioncomm (priority, fulldayevent, location, label, fk_element, elementtype, fk_project, datep, datef, percentage, note)
SELECT 0, 0, '', 'prova', id, 'project_task', fk_project, date_start, date_end, progress, description
FROM inserted;
END;
/
But when I execute says this errors:
Errors: TRIGGER CREATE_EVENT_FROM_TASK
Line/Col: 2/2 PL/SQL: SQL Statement ignored
Line/Col: 4/7 PL/SQL: ORA-00942: table or view does not exist
Can anyone help me?
I think it got this error because of the select query inside the trigger. Check if the user which called the trigger has the grant to execute select from the "inserted" table.
https://www.tekstream.com/resource-center/ora-00942-table-or-view-does-not-exist/
Ora-00942 means you are attempting to execute an SQL statement that references a table or view which does not exist. There are several possible causes for the “table or view does not exist” error, including:
1) Referencing a table or view that does not exist
2) Using an unauthorized synonym
3) Using an expression of view where a table is required
4) Attempting to use a table without proper permission or privilege
inserted is part of SQL Server. I think you want:
BEGIN
INSERT INTO llx_actioncomm (priority, fulldayevent, location, label, fk_element, elementtype, fk_project, datep, datef, percentage, note)
SELECT 0, 0, '', 'prova', :new.id, 'project_task',
:new.fk_project, :new.date_start, :new.date_end,
:new.progress, :new.description
FROM dual;
END;

Insert data in a case statement in Hive

Is it possible to insert a new row of data in a case statement in Hive.
I have a basic 'team' table, with the following fields (team_id,fname,lname).
This is what I am trying to run,
SELECT team_id,fname,lname,
CASE WHEN team_id = 2 THEN insert into team values (20, 'billy', 'bob'); ELSE "" END team_id
FROM team order by team_id;
Error ParseException line 2:29 Failed to recognize predicate 'insert'. Failed rule: 'identifier' in table or column identifier
If anyone could provide and info or solution, it would be great
Frostie
Afaik we can't put any ddl or dml operation in case statement in hive. But workaround can be applied to solve above problem, if really needs to be solved.
insert into table team select 20, 'billy', 'bob' from team where team_id = 2;
Explanation:- it will insert a new record in team table if team_id=2 else nothing to insert.

Inner query not throwing error in postgres

There is a scenario in which we are retrieving some result from inner query and using the result to perform some operation
create table test1(key integer,value varchar)
insert into test1 values(1,'value 1');
insert into test1 values(2,'value 2');
insert into test1 values(3,'value 3');
second table as
create table test2(key1 integer, valuein varchar);
insert into test2 values (2,'value inside is 2');
insert into test2 values (4,'value inside is 4');
insert into test2 values (5,'value inside is 5');
the below query is giving result but in my view it should give an error
select * from test1 where key in
(select key from test2)
because key column does not exist in test2 table.
but it is giving result in postgres
but when run in oracle it is giving error as
ORA-00904: "KEY": invalid identifier
00904. 00000 - "%s: invalid identifier"
This is the correct behavior as specified in the SQL standard. The inner query has access to all columns of the outer query - and because test1 has a column named key (which, btw is a horrible name for a column) the inner select is valid.
See these discussions on the Postgres mailing list:
http://postgresql.nabble.com/BUG-13336-Unexpected-result-from-invalid-query-td5850684.html

SELECT a table from oracle data dictionary

I am new to SQL and recently installed Oracle 11g. I read the post here on selecting all tables from user_tables. I'm trying to select a specific table and following some of the suggestions in the post does not appear to work.
The following executes fine and returns all tables available to me including a table named faculty_t:
select * from user_tables;
select * from dba_tables;
select * from all_tables;
desc faculty_t;
But I get error when I do the following:
select * from user_tables where table_name = FACULTY_T;
The first set of statements confirm that I do have a table named faculty_t. However, trying to select this table from user_tables, all_tables, or dba_tables does not appear to work for me right now. The error message reads something like:
ORA-00904: "FACULTY_T": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 208 Column: 8
Any thoughts? Thanks!
String literals in SQL are wrapped in '. So:
select * from user_tables where table_name = 'FACULTY_T';
When you did a desc faculty_t, the SQL engine knew that a table name was expected at that spot (the syntax expects a table name there). But in your select query, sql is just looking for the value of a column that happens to have a string data type, so you need to use the ' for a string literal.

Resources