My table is sqlite3 is created with the following:-
'CREATE TABLE IF NOT EXISTS gig_program ( gig_program_id VARCHAR(20) PRIMARY KEY );'
When I try to insert data into the table using python 3.8 with the following:-
sql = 'INSERT INTO gig_program ( gig_program_id ) VALUES ( "20200524120727" );'
cur.execute(sql)
the following exception was thrown:-
near "gig_program": syntax error
When I cut and past the insert command to the sqlite3 console, it works.
I have also tried using another editor for the program (thinking that there may be hidden characters) but the result is the same.
I would appreciate help. I have used similar methods in other parts of the program to insert data and they work without issue.
Thank you for looking into my questions.
I found that it was actually my mistake. The exception was actually for a second sql statement which I missed out the "FROM" word.
Thank you everyone for your time.
Hope everyone is doing well.
Related
I am new to Python and I want to execute multiple SQL queries in one statement using python, but I am not able to find the appropriate way to do so.
I wrote following code but its throwing an error as " DatabaseError: ORA-00933: SQL command not properly ended."
import cx_Oracle;
SQLQuery = "select x from xyz where p= 'sn'; select * from abs where a ='qw';"
connection = cx_Oracle.connect('username', 'password', 'server')
cursor = connection.cursor()
cursor.execute(SQLQuery) #its throwing error here
It would be great if one can suggest me the appropriate function for executing the multiple queries in one call.
Appreciate your response. Thanks in advance.
What do you want to achieve with this?
Technically you could try to get rows from two tables or try to combine rows from different tables, but all this is directly done in SQL.
Remove ; (semicolon) at the end of query and it should run fine.
This question may seem rudimentary but nothing that I have found online quite fits.
I am looking at an old FOXPRO script that we used to make a table. At the moment, I am attempting to translate this script into SQL. Of note is the following,
delete all for code='000000'
pack
If I understand this correctly, it deletes all rows/records where the code field has a value of 000000. Am I correct?
"Into SQL"
What do you mean by "SQL"?
Do you mean do the same thing using SQL in VFP for a VFP table? If so then:
use myTable exclusive
delete from myTable where code = '000000'
pack
But I doubt you are asking this, when you could do it by simply using the xBase code you wrote.
Do you mean how to that in an SQL backend like MS SQL server. postgreSQL, MySQL ...? If so then:
delete from myTable where code = '000000'
Note: In your code "all" is unnecessary but wouldn't do any harm.
Note2: In VFP code that you wrote, first line is "marking" the rows as "deleted" that have code value '000000'.
Second line really removes those rows from the table.
What version of foxpro?
delete from [table] where code = '00000'
pack
or
delete for code = '000000'
pack
both should work
I am new to SQL stuff in blueprism, I am able to configure SQL object and execute simple queries, but I am facing trouble while trying to run multiline complex SQL queries.
when I was trying to execute the below query in blueprism, getting some error message, saying "Incorrect Syntax near Database2"
"select top 10 * from [Database1].[dbo].[Table1]
join [Database1].[dbo].[Table2] on [Database1].[dbo].[Table2].Fieldname1=[Database1].[dbo].[Table1].Fieldname2
join [Database2].[dbo].[Table1] on [Database2].[dbo].[Table1].Fieldname1=[Database1].[dbo].[Table2].Fieldname2"
Can somebody please help me, what was the wrong in the above query...
I found the answer myself, there should not be any additional white space characters in the query, entire query should be in continuous line. The beauty of blueprism is, it can execute any level of complex queries without any constraints, but need to modify the syntax accordingly. always we should mention the filename and table names in the following format - [databasename].[dbo].[tablename].[fieldname]
I am trying to use excel to update a list of part numbers in my database:
UPDATE
stock s
SET
s.STC_AUTO_KEY = 2
WHERE s.WHS_AUTO_KEY = 2 AND
EXISTS(
SELECT
p.PNM_AUTO_KEY
FROM
PARTS_MASTER p
WHERE
s.PNM_AUTO_KEY=p.PNM_AUTO_KEY AND p.PN='102550');
UPDATE
stock s
SET
s.STC_AUTO_KEY = 2
WHERE s.WHS_AUTO_KEY = 2 AND EXISTS(
SELECT
p.PNM_AUTO_KEY
FROM
PARTS_MASTER p
WHERE
s.PNM_AUTO_KEY=p.PNM_AUTO_KEY AND p.PN='204-060-444-003');
The statements run without semicolons, but when I try to run more then one at once and use semicolons I get the error:
SQL Error [911] [22019]: ORA-00911: invalid character
java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
so... it looks like I don't know how run run more then one basic statement at once.
I am using DBeaver to interact with a Oracle database.
Thanks guys, sorry if this a no-brainer.
Try adding a blank line between each update statement if possible. You can do this easily with a text editor that supports regular expressions, just replace ';\n' with ';\n\n'
I'm using psycopg2, and the query is a simple string.
Q= "SELECT * FROM POST WHERE PUBLISH_TIME IS NULL"
When I execute it in pgAdmin, it gives me the correct results, but throws
psycopg2.ProgrammingError: column "publish_time" does not exist
I tried this solution
but it's still the same error output.
Leaving this answer here in case anyone has the same problem. This cannot be done via psycopg2 due to a design feature. I added a flag to my model which depended on publish_date column, created a db script that wrote this flag and went ahead with
Q= "SELECT * FROM POST WHERE PUBLISH_FLAG = False;"