Querying an apostrophe in R - sql

In SQL, you are supposed to query a name such as "St. John's" as 'St. Johns'''s, where you replace the single quotes with two single quotes, or you can use double quotes and not do the double single quote. However, no matter what I try in R, it still tells me "unexpected string literal". Any help would be appreciated.code and error

Remove the quote characters around your database, schema and table name.

Related

How to insert a char value enclosed in square brackets. Getting error column 'value' does not exist in the 'table'?

Hi,
I am trying to insert a value "['HCC111', 'HCC112']" in a redshift column but getting an error which says column "['HCC111', 'HCC112']" does not exist in the table. Is there a workaround for this ?
Query:
insert into #trhcc values('COMMUNITY V22', "['HCC111', 'HCC112']",'HCC10')
Here is the snapshot of the query that is submitted --
"['HCC111', 'HCC112']" is not a valid way because you used doube quotes. Text must use single quotes. Your problem is that you also use single quotes in your entry text. That is easily solved by escaping your single quotes. You do that by doubling the single quote like so:
'[''HCC111'', ''HCC112'']'

How to Post a SQL String With Quotes?

This seems like it would be a question that has been answered a million times before, but searching for a bit only brought up replacing single quotes with double quotes.
The problem is that I have a file with a huge number of single quotes. Is there any way to insert a string as is, without the single quotes throwing an error. Any wrapper?
This is for pure SQL, I don't need to save this string from the backend or anything. I need a SQL command.
Edit: Just to clarify - the string I am trying to post is a document, in html format, with a large number of both double and single quotes, escaping each one individually would take enough time to warrant saving data in another format, which I would rather not do.
If you have a file accessible to the SQL Server, you can read the contents in to a variable with OPENROWSET. For example, to read a Unicode text file at C:\drop\demo.html:
DECLARE #DocumentText nvarchar(MAX);
SELECT #DocumentText = BulkColumn
FROM OPENROWSET(BULK 'C:\drop\demo.html', SINGLE_NCLOB) file;
INSERT INTO Files (Column) VALUES (#DocumentText);
Can you replace the single quotes with two single quotes? That is how SQL Server escapes the single quote in a string.
declare #test_string nvarchar(max) = 'string with a single '' quote in it';
print #test_string
string with a single ' quote in it
You need to use double quotes:
select 'it''s a double quote'
Will return:
it's a double quote
Read the file, parse it, and do
if(string.charAt(I))=="'"... charAt(I)="";

Insert query for HTML string containing single and double quotes

I have Sql database with table name QUESTION
I want to insert value for QuestionTitle as html string contains single and double quots.
Insert query is
INSERT INTO QUESTION (QuestionType,QuestionID,QuestionTitle)
VALUES("MRQ","QNB5T6TKDMS",'<h1>What are types of special symbols
like #.~!#!$%^&*()_['"+-=</h1>')
When I try to execute this query in Sql it gives an error ,unrecognized token: ""+-=')" .
I try for \' and \'' ,still not work.
How can I do this so that it will work for html string.
The apostrophe, or single quote, is a special character in SQL that specifies the beginning and end of string data. This means that to use it as part of your literal string data you need to escape the special character.
The first one works fine for MySQL
INSERT INTO QUESTION (QuestionType,QuestionID,QuestionTitle) VALUES(8,"QNB5T6TKDMS",'<h1>What are types of special symbolslike #.~!#!$%^&*()_[\'"+-=</h1>')
or
This will work in SQLite
INSERT INTO QUESTION (QuestionType,QuestionID,QuestionTitle) VALUES(8,"QNB5T6TKDMS",'<h1>What are types of special symbolslike #.~!#!$%^&*()_[''"+-=</h1>')

Quotes in a long multi-variable SQL request in Basic4android

All B2A users.
Again about double quotes in SQL: how to be (replace quotes) in B2A long SQL INSERT\UPDATE request string, if this string is created dinamically, fields names and qty are variables (download by HTTP), and any value of them can be a string with quotes ?
Fields values are also in double quotes for INSERT, and I mean that whole the big SQL string cannot be easy formatted as string with & QUOTE & parts.
B4A gives SQLite exception "sintax error". Quotes in the values must be saved\used.... :-( not to be replaced by two single quotes.
What more symbols in the fields values must be specially checked (excepting destructive SQL injections...)?
The solution is to use parameterized queries with ExecQuery2 or ExecNonQuery2. SQL docs.
You can also use DBUtils.

Single Quote Error

When I insert single quote in search box and press search button it gives error like:
[Microsoft][SQL Server Native Client
10.0][SQL Server]Unclosed quotation mark after the character string ' '.
You should be using parameterized queries instead of constructing your SQL by concatenation.
This will avoid SQL Injection attacks as well as resolve any single quote issues.
The quick fix it to escape the ' by doubling it (''), but this would just be a temporary workaround and your code will still be vulnerable.
Parameterize your SQL queries. There are more serious issues than this called SQL Injection.
You need to escape single quotes, like \' as you're using single quotes to surround where-statements, like where i = 'foo', then you need to write where i = '\'' to match a single quote, or lie where i = 'it\'s a good day today'