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.
Related
My goal is to iterate through a set of values and use them to run a set of queries that will insert their results into a hive table using pyodbc.
I tried
params = ['USA','JP']
set(params)
for i in params:
cursor.execute(insert into table **some_db.some_tbl** SELECT name, country from **some_db.some_tbl_2** where country = ?,i)
And got the error
the following and received the error message, ProgrammingError: ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000').
If I remove the insert into table some_db.some_tbl portion, it works fine. Not sure what else to do as all documentation and looking at similar questions suggest what I am doing is correct.
If I keep the insert into table some_db.some_tbl portion but remove the parameterization, it works fine.
I am answering this question with a simple workaround as it might help save someone else some time.
Since the 'insert without parameterization' and a 'select with parameterization' work independently, I worked around this issue by looping through my parameters with a select statement and then saving the results to a pandas dataframe. From there, you can then run the insert against the pandas dataframe without parameterization for the current iteration. All of this would be in the body of the loop thus accounting for all parameter values separately.
I get the following error, I haven't had this issue before and was wondering if lvscat is an alias for something. From what I read that is a common issue, but even if it is that I am still unsure of how to fix it. This is the full Error
[DataDirect][OpenEdge JDBC Driver][OpenEdge] Column "LVSCAT" cannot be found or is not specified for query.
Here is the query:
INSERT INTO PUB.lvsbk (BookingNo, LvsCat)
VALUES (1007265, 'G')
Mapping with SQL Interface:
It is possible that the column was defined as "lvsCat". That means that the case is important.
Unfortunately, you have to use the double quotes to reference it:
INSERT INTO PUB.lvsbk (BookingNo, "LvsCat")
VALUES (1007265, 'G') ;
If this is the case, you might want to recreate the table without escaping the name of identifiers.
I am unsure what tool you are using to demonstrate the definition of your table, but you can view the actual definition of your table with:
select * from sysprogress.syscolumns where tbl = 'lvsbk';
Alternatively a simple:
select top 1 * from pub.lvsbk;
May provide enough evidence as to what your column is actually called.
I found the issue, it was because the field simply didn't exist.
My work is testing out Postgres. I usually write in SQL using SAS with Oracle and Teradata syntax. Our test database has a really sloppy table in which every column was created as a character 255. I have a very simple thing I'm trying to do but it's not working. I want to create a new table and reformat from 255 to 10. I also want to remove all the trailing blanks. Also, "IS NULL" is not working. Even when there is nothing visible for a value.
PROC SQL;
CONNECT TO POSTGRES(&connectstuff);
EXECUTE(CREATE TABLE common.UNQ_NUM_LIST AS
SELECT DISTINCT UNIQUE_NUM,
BTRIM(PAT_ACCT) AS PAT_ACCT
FROM ACCT_DATA.ACCNTS
) by postgres;
DISCONNECT FROM POSTGRES;
QUIT;
I want to create PAT_ACCT as a character 10 format but not sure how. Can I indicate a new format when creating a table? Everything I've tried didn't work. Even the BTRIM doesn't actually seem to get rid of the trailing spaces on that value either. And again, null values aren't being recognized with "IS NULL". I feel like this should be very simple!
To influence the data type, cast the result column in the query appropriately:
CAST (btrim(pat_acct) AS character(10)) AS pat_acct
There is, however, no way to set a column NOT NULL that way.
I recommend that you execute two statements: one that creates the table the way you want it, and another one like
INSERT INTO ...
SELECT ... FROM ...
I was trying to use sqlFetch. The fetch works perfectly when I change the name of my table to have underlines instead of periods. So if I use the command
sqlFetch(conn, "HelloWorld_40")
It works fine. Unfortunately, my friends are all using the real name of the table
sqlFetch(conn, "HelloWorld.40")
But then it crashes and it tells me that
Error in sqlColumns(conn, "HelloWorld.40") :
'HelloWorld.40': table not found on channel
I'm guessing the period "." is illegal name for a table. But I don't want my friends to change it because it's a lot of people who would be affected. Is there a way I can call the table, or do I have to secretly go to their database, change the name while I use it and then change it back to a period (risking that I will forget, someone will read, blah blah).
Thanks.
put the table name in square brackets:
[HelloWorld.40]
It is a problem with sqlFetch which parse table name. Unfortunately it did not handle table quotes, so it's search for table 40 in schema HelloWorld. You need to directly call sqlQuery (with quoted table name, brackets for MS SQL Server):
sqlQuery(dbhandle, "SELECT * FROM [HelloWorld.40]")
Side note: you should specify which database you are using.
The best delimiter is double quotes -- that should work in most underlying databases:
"HelloWorld.40"
In MySQL, you can also use back ticks (`):
`HelloWorld.40`
In SQL Server, Access, and I think Sybase, you can also use square braces:
[HelloWorld.40]
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');