I made an insert statement that runs inside a asp.net page. It gave me an error, so I went to the sql server and ran the statement as it should be and used it to compare with what I wrote in the asp.net page. The thing is, it it writen properly but it doesn't work. It can't seem to detect the database or the tables at all and tells me the table doesn't exist and neither do the colums. The statement looks like this:
INSERT [Remisiones].[dbo].[Places] (Name, Type) VALUES ("Planta 1", "Planta")
I have also tried using [dbo].[Places] and simply Places but it gives me an error at the place of the table saying it is an Invalid object name. What is it doing?
Don't use double quotes for string delimiters; use single quotes.
INSERT [Remisiones].[dbo].[Places] (Name, Type) VALUES ('Planta 1', 'Planta');
Related
This question already has answers here:
Insert text with single quotes in PostgreSQL
(8 answers)
Correctly delimit single quotes in postgres insert/update
(1 answer)
Closed 4 years ago.
I'm writing a function that logs interactions with a Facebook messenger bot. Anything the user says is logged in a PostgreSQL database.
My insert statement looks like this:
INSERT INTO interactions (fbid,date,time,event) VALUES ('senderid','2018-10-
01','11:15:48','text')
Treat "senderid" as a 20-digit number and "text" as whatever the user says.
Now, the above statement works IF the text from the user contains no apostrophe characters. However, sometimes the text DOES contain apostrophes. In these cases, the insert doesn't work.
For example, if the user says "Let's chat" then my SQL looks like this:
INSERT INTO interactions (fbid,date,time,event) VALUES
('senderid','2018-10-01','11:15:19','Let's Chat!')
and I get the following error:
Query result: error: syntax error at or near "s"
I know this is because I would need to escape the apostrophe. I've tried working around this by using double quotes in my insert statement, like this:
INSERT INTO interactions (fbid,date,time,event) VALUES ("senderid","2018-09-
28","10:50:07","Let's chat")
But when I do this I get the following error:
ERROR: column "senderid" does not exist
So I have two questions:
CAN I use double quotes in a SQL insert?
If I CAN'T use double quotes in a SQL insert, how would I escape an apostrophe character, bearing in mind there may not always BE an apostrophe?
Try below: you need to use single quote twice in case of apostrophi like let's will be let''s
INSERT INTO interactions (fbid,date,time,event) VALUES ('senderid','2018-09-
28','10:50:07','Let''s chat')
1.CAN I use double quotes in a SQL insert?
no you can't because double quote means column name in postgrey that why when sql engine found that column when you use double quote
you can use
'Let''s Chat!'
I need to execute a simple INSERT INTO query on an old Access97 database.
I'm starting with a very short example - which doesn't work:
INSERT INTO [MY-TABLE]( [Field1] )
VALUES ( "blabla" )
MY-TABLE is the actual name of the table and Field1 is a String field.
I get the error:
Query input must contain at least one table or query
Because I need to insert literal value, I don't want to use a query here (i.e. a SELECT FROM)
Reading also the docs (https://msdn.microsoft.com/en-us/library/bb208861(v=office.12).aspx) I don't see where my SQL is wrong.
UPDATE
Here a couple of screen shot of the actual table and fields:
here the SQL code:
Anyway...
SOLVED!!
It works even with double quotes.
The problem was the push button I was using to check: using the "View" button leads to the error above. Instead I must use the "exclamation mark".
I need to execute the query using the "exlamation mark" button instead of the view one. This is because my query has not a result set to view - hence the error I saw.
By the way I confirm the syntax is accepted both with single or double quotes.
I have a table in a database that looks like this
I want to insert a new record. So I right click on my table, hover over 'script table as' and select the 'INSERT to' option
When I do this, I get this
My question is, what is wrong with this syntax? I seem to be getting an error before even trying to add anything. When hovering over the red lines, I get a message saying
'Incorrect syntax near <'
&
'varchar is not a recognized built in function name'
I assumed I would replace the second part with my data values. But I'm not sure.
You need to input actual values.
INSERT INTO tab_name(First_Name, Last_Name, ...)
VALUES ('John', 'Smith', ...);
Replace <col_name, datatype> placeholder with actual data.
You can also Use Templates in SQL Server Management Studio to fill template values.
Query -> Specify Values for Template Parameters
or
Highlight your query and press CTRL+SHIFT+M
I'm trying to insert with select statement, but I get the error saying that I have syntax error with insert into statement.
insert into S2T_BL(note)
SELECT S2T.[work]
FROM S2T;
Just select works fine itself:
SELECT S2T.[work]
FROM S2T;
Even trying insert without that column works fine, where desc is not memo data type:
insert into S2T_BL(desc)
SELECT S2T.[desc]
FROM S2T;
S2T.[work] and S2T_BL.note are both MEMO data type, so I believe problem related with data type. Any suggestions?
Your problem is actually not due to Memo datatype. Rather the problem is because note is a Jet reserved word.
I created S2T_BL and S2T tables with note and work Memo fields. Then enclosing the name note in square brackets allowed this query to execute without error:
INSERT INTO S2T_BL([note]) SELECT S2T.[work] FROM S2T;
Without the square brackets ... ie INSERT INTO S2T_BL(note) SELECT S2T.[work] FROM S2T ... I got a syntax error as you reported.
Reserved words are a common cause of Access query problems, so it's best to avoid them if possible. When you can't avoid them, at least beware of them so you can take precautions. In case you're unsure which words are officially reserved or otherwise problematic, you can use Allen Browne's Database Issue Checker Utility to examine your database. In addition to reserved/problem names, it can also warn you about other issues which may complicate your Access development.
I am a beginner in SQL, and I was having some trouble with special characters like parentheses and asterisks in user generated data. So far, I have mostly been using a lot of ad hoc methods of getting rid of these characters and they work well enough. Based on what I have read, I think paramaterized queries might be a more systematic way of getting around some of the problems that I have.
I have following query:
insert into midstep (street)(select street from addresses limit 10)
The column street in the table addresses has a lot of parantheses, asterisks etc. The code above works as expected. What I want to do is something like this:
prepare midstreet (text) AS insert into midstep (street)(select $1 from addresses limit 10);
execute midstreet ( street from addresses);
However, when I enter in that code I get the following error message:
ERROR: syntax error at or near "from"
SQL state: 42601
Character: 29
I have tried a bunch of variations on this code and read through the documentation on Prepare and Execute but always get error messages. Any help is appreciated!
EDIT: I forgot to mention, I am using postgresql 9.3 on and my os is Ubuntu. Please ask if you need any more information to help!
You do not need a parameter in your case, as you get your values using a sub-query. As a matter of fact, you cannot know the needed values on server-side. Parameters like that are needed if and only if you have some values defined on application level and you want to pass them to the database.