SQLITE escape comment "--" - sql

I'm using DB Browser for SQLite, doing multiple inserts. However I need to escape -- but it just keeps giving me errors.
INSERT INTO table(name) VALUES ("S6--sfI6H6E"),("ASGts7sa6jw") -- Error at S6
I have tried the following:
INSERT INTO table(name) VALUES ("S6\-\-sfI6H6E"),("ASGts7sa6jw") ESCAPE '\' - Error at ESCAPE
INSERT INTO table(name) VALUES ("S6\-\-sfI6H6E"),("ASGts7sa6jw") - Inserts Literal String
INSERT INTO table(name) VALUES ("S6'-'-sfI6H6E"),("ASGts7sa6jw") - Inserts Literal String
INSERT INTO table(name) VALUES ("S6----sfI6H6E"),("ASGts7sa6jw") - Error at S6
How can I escape --?

Related

Special characters in bulk insert query

I need to pass this query :
BULK INSERT e-Alexie.ENTREPRISE\beulin-ma.Correspondance_RCU_PP
FROM '\\ST077283\C:\Users\P20M511\Documents\Test_RCU.csv';
but I get an error on the - character. I've tried with ^_-^_ but it didn't work
Any idea?

Insert ARRAY in PostgreSQL table with apostrophes in values

I have a Python script with SQL insert statements that insert parsed data from file to PostgreSQL table. In case data has apostrophes, execution fails. In detail:
<name>RYAZAN'</name>
or
<name>CHYUL'BYU</name>
I found the solution when it is a string -> adding extra ' to apostrophe so it transforms to 'RYAZAN''' or 'CHYUL''BYU' in INSERT statement.
But in case my values are in list (from python script) like city = ["RYAZAN''", "CHYUL''BYU"] Python automatically puts double quotes instead of single quotes. As a result when trying to insert
INSERT INTO City (uuid, name) VALUES (uuid_generate_v4(), unnest(array{city}))
SQL fails with error
ERROR: column "RYAZAN''.." does not exist
because sql reads the double quotes as a column name or whatever. Is there a way to insert ARRAY with values that contain apostrophes?
Try using $$ dollar-quoted strings
CREATE TEMP TABLE t (f TEXT);
INSERT INTO t VALUES ($$<name>CHYUL'BYU</name>$$),
($$<name>RYAZAN'</name>$$);
SELECT * FROM t;
f
------------------------
<name>CHYUL'BYU</name>
<name>RYAZAN'</name>
(2 Zeilen)
There are also many other ways to escape quotes
INSERT INTO t
VALUES (E'\'foo'),('''bar'''),
('"the answer is" -> ''42'''),($$It's "only"" $1.99$$);
SELECT * FROM t;
f
-------------------------
'foo
'bar'
"the answer is" -> '42'
It's "only"" $1.99
(4 Zeilen)
Demo: db<>fiddle

Inserting Special Characters in SQL insert query

The sql statement I am trying to execute is
INSERT INTO Scanners (Character) VALUES ('~')
The characters I would like to insert are:
{,}, [, ^ , & , ~, ` , : , ;.
But it says syntax error. Any help would be appreciated.
You can try to use [].
INSERT INTO [Scanners] ([Character]) VALUES ('~')
You can use the Chr function to insert special characters. So for example, to insert '~', you could do the following:
INSERT INTO Scanners (Character) VALUES ('' || Chr(126) || '') -- 126 is ascii for ~
Note, I'm not in front of my machine with environment set up to test this.

Single and double quotes in SQL Server

I want to know exact reason why this error occur playing with quotes.
INSERT INTO table_check(name) VALUES('hello'hi') -- ERROR
INSERT INTO table_check(name) VALUES('hello''hi') -- RESULT:- hello'hi
INSERT INTO table_check(name) VALUES('hello'''hi') --ERROR
INSERT INTO table_check(name) VALUES('hello''''hi') --RESULT:- hello''hi
INSERT INTO table_check(name) VALUES('hello'''''hi') --ERROR
INSERT INTO table_check(name) VALUES('hello''''''hi') --RESULT:- hello'''hi
Single Quotes are Escaped by Doubling Them up.So whenever even number of Quotes are present, then we get the Result.
To Know The Behavior of Single Quotes Try to Run This Below Code:
Select '','''','''''','''''''',''''''''''
So,Single Quotes Should be Even Number Else We get error like:Unclosed quotation mark after the character string ') -- ERROR

Insert a String Value with Semicolon Causes Error

How can I escape a semicolon in a string for insert into an SQL database table?
Example:
Insert Into items(Description)
Values('Anti Surge T; LBC Slow Blow 6.3 x 32mm 7A / 250V');
semicolon in a string should not cause any problem, still enclose the string in single quotes in insert statement.