Sybase interacting with mybatis - syntax-error

Im unable to insert multiple records in a single transaction. Im using foreach in mapper and I'm getting incorrect syntax near ','.
I googled and found, in sybase it's not possible to insert multiple rows in sybase.
Insert statement looks like:
insert into Student(id,name)
values (1, Jon), (2,mike),(3,sam)
Comma next to value statement, is creating issue.

Related

Error in using with statement with PostgreSQL insert query

I am trying to use a with clause with postgres insert statement
with inserted_record as (insert into person_age(person_name, years_old) values ('asnim', 21) returning *);
However, it errors out like
SQL Error [42601]: ERROR: syntax error at end of input
Position: 108
If i run it with without the the with clause it works
insert into person_age(person_name, years_old) values ('asnim', 21) returning *;
What am I missing here?
A CTE (WITH clause) is part of an SQL statement and cannot stand on its own. PostgreSQL complains about an error at the end of the statement, because it expects a following SELECT, INSERT, UPDATE or DELETE.
In a way, a CTE is like a view defined only for a single statement. You cannot define a CTE and then use it with several statements; for that, you could define a temporary view in the pg_temp schema.

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.

insert into using Values

I am am using sql server 2005 and doing a simple insert into and getting an incorrect syntax error. I See nothing wrong with my code Can someone give me some ideas what could be wrong with it?
insert into inonhd
(fpartno,fpartrev,flocation,fonhand,fcudrev)
Values
('CRV109','1','11','01','1'),
('CRV110','0','11','01','0')
the error is Incorrect syntax near ','.
You must add each row in separate command.
insert into inonhd
(fpartno,fpartrev,flocation,fonhand,fcudrev)
Values
('CRV109','1','11','01','1')
and:
insert into inonhd
(fpartno,fpartrev,flocation,fonhand,fcudrev)
Values
('CRV110','0','11','01','0')
It is really important to note that the syntax in the question is fine for more recent versions of SQL Server. This is acceptable:
insert into inonhd(fpartno, fpartrev, flocation, fonhand, fcudrev)
Values ('CRV109','1','11','01','1'),
('CRV110','0','11','01','0');
If you want to do this in one statement, you can use select . . . union all:
insert into inonhd(fpartno, fpartrev, flocation, fonhand, fcudrev)
select 'CRV109','1','11','01','1' union all
select 'CRV110','0','11','01','0';
Of course, multiple inserts are another possibility.

Insert statement in sql with one field set as autonumber

I am having three columns in my table branch i.e id(Autonumber),code(text),desc(text).I am trying to execute this sql
insert into branch(code,desc) values('"+b+"','"+c+"')";
which gives me error syntax error..please help
One of your columns has name DESC, which is Reserved Keyword. In order to peoperly execute the INSERT statement, you need to delimite the column by using brackets eg
insert into branch(code,[desc]) values ('"+b+"','"+c+"')";
MSACCESS Reserved Keywords List
One more thing, your code is prone to SQL Injection. Please do parameterized the query.

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.