I've written a simple trigger using HDBC and Sqlite3.
calculateNoOfStocksTraded::Database.HDBC.Sqlite3.Connection->IO Integer
calculateNoOfStocksTraded conn=do
run conn "CREATE TRIGGER calStocks\
\AFTER INSERT ON historicalData\
\FOR EACH ROW\
\BEGIN\
\UPDATE company\
\SET noOfStocks=300.0;\
\END " []
It keeps saying that there's a syntax error. I don't know how to figure it out. pls help me to locate the error
The pieces of your SQL strings are being run together without spaces between them (because that's how the string breaks with \ work in Haskell). Try adding a space at the end of each line of the query, before the \.
Related
I have the following task in my DAG:
create_features_table = PostgresOperator(
task_id="create_features_table",
postgres_conn_id="featuredb",
sql="src/test.sql "
)
But when I test the task, I get this error:
psycopg2.errors.SyntaxError: syntax error at or near "src"
LINE 1: src/test.sql
The content of the test.sql script is:
CREATE TABLE test(
C1 int,
C2 int,
);
I can't point out the error in the syntax, but that's because it is my first DAG. Any help would be greatly appreciated.
If I run the script directly from the postgres container's psql using "\i src/text.sql" it works fine.
I have tested the connection from the airflow web server and the connection works.
I found that I had to put a space before closing the quotes to avoid a jinja2.exeptions.TemplateNotFound error, but haven't been able to find the syntax error.
According to documentation (https://airflow.apache.org/docs/apache-airflow-providers-postgres/stable/_api/airflow/providers/postgres/operators/postgres/index.html#airflow.providers.postgres.operators.postgres.PostgresOperator)
if you are defining your sql script path, it must ends with .sql
You have a white space in your path in the end so Operatort things it’s a query to be executed on your postgre, not file with query. You can see it in the response from postgre. Run this query on your postgre instance src/test.sql and you will get the same syntax error.
You can fix it easily by removing that white space
sql="src/test.sql"
I'm pretty new at stored procedures and I get the following syntax error in my code:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER //CREATE PROCEDURE sp_create_probe(IN matrix_id INT, IN oligo_id IN...' at line 2
Here's the code for my procedure:
DELIMITER //
CREATE PROCEDURE sp_create_probe(IN matrix_id INT, IN oligo_id INT)
BEGIN
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO Probes (oligo, microarray) VALUES (oligo_id, matrix_id);
SET FOREIGN_KEY_CHECKS=1;
END //
DELIMITER ;
Hope someone can help me out
EDIT:
Well I ended up fixing it. Classic noob mistake.
I had this line before the code you see above:
DROP PROCEDURE IF EXISTS sp_create_probe
Didn't copy that line into the post for some reason but it's missing the ";" at the end. That fixed it.
I'm new to robot framework. I'm trying to create a Keyword in my suite to login to DUT, run a command and fetch the output. but the prompt of the DUT is constantly changing. Following is the keyword and also the command output in DUT.
Keyword snippet:
Write show table sys ClassOfService
${output}= Read Until Regexp admin#0-9 .*\>
command output in DUT:
admin#0-9 19:36:44> show table sys ClassOfService
profileXml "<?xml version=\"1.0\" encoding=\"UTF-8\"?><cos version=\"1.0\"> <PublicIdentifiers>
</PublicIdentifiers> \t\t\t </cos>";
[ok][2020-04-11 19:36:45]
admin#0-9 19:36:45>
But it is always getting timeout. Please let me know if I'm missing something.
Thanks in Advance
Your regular expression looks good, but in Robot Framework the > must have the \ escaped with another \. Look at the example for Read Until Regexp. Your final command should be:
Write show table sys ClassOfService
${output}= Read Until Regexp admin#0-9 .*\\>
I have a text file that contains some basic passwords and some variants of those basic passwords. They are typed out together like this:
qwerty, qwerty1
password, password1
default, default 1
123, 12345, 123456
I am trying to take these values and split them, storing them in a tuple and then print out the values as 'Password' and then any variants, but I am getting a syntax error on the print BIF? (I am aware this will not print out the password '123456', I am just trying to solve the syntax error first.)
for each_line in passwords:
(passwd, passwd_variant) = each_line.split(',',1)
print(f'Password: {passwd}, Variant {passwd_variant}')
SyntaxError: invalid syntax
normally if I was writing a script, in the editor I would put print on a new line, however a new line in IDLE simply executes the code above it. is there a shortcut or something to do a carriage return and write the print statement on a new line and if so, is that the cause of the syntax error and why?
Cheers
EDIT: I would like my output to be this
Finally discovered that you need to hit Enter after the for in statement, this will then take you to a new line inside for in statement. Was up all night trying to work it out, maybe my fresh brain helped this morning.
Background: I am developing a rscript that pulls data from a mysql database, performs a logistic regression and then inserts the predictions back into the database. I want the entire system to be self contained in the script in case of database failure. This includes all mysql stored procedures that the script depends on to aggregate the data on the backend since these would be deleted in such a database failure.
Question: I'm having trouble creating a stored procedure from an R script. I am running the following:
mySQLDriver <- dbDriver("MySQL")
connect <- dbConnect(mySQLDriver, group = connection)
query <-
"
DROP PROCEDURE IF EXISTS Test.Tester;
DELIMITER //
CREATE PROCEDURE Test.Tester()
BEGIN
/***DO DATA AGGREGATION***/
END //
DELIMITER ;
"
sendQuery <- dbSendQuery(connect, query)
dbClearResult(dbListResults(connect)[[1]])
dbDisconnect(connect)
I however get the following error that seems to involve the DELIMITER change.
Error in .local(conn, statement, ...) :
could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER //
CREATE PROCEDURE Test.Tester()
BEGIN
/***DO DATA AGGREGATION***/
EN' at line 2
What I've Done: I have spent quite a bit of time searching for the answer, but have come up with nothing. What am I missing?
Just wanted to follow up on this string of comments. Thank you for your thoughts on this issue. I have a couple Python scripts that need to have this functionality and I began researching the same topic for Python. I found this question that indicates the answer. The question states:
"The DELIMITER command is a MySQL shell client builtin, and it's recognized only by that program (and MySQL Query Browser). It's not necessary to use DELIMITER if you execute SQL statements directly through an API.
The purpose of DELIMITER is to help you avoid ambiguity about the termination of the CREATE FUNCTION statement, when the statement itself can contain semicolon characters. This is important in the shell client, where by default a semicolon terminates an SQL statement. You need to set the statement terminator to some other character in order to submit the body of a function (or trigger or procedure)."
Hence the following code will run in R:
mySQLDriver <- dbDriver("MySQL")
connect <- dbConnect(mySQLDriver, group = connection)
query <-
"
CREATE PROCEDURE Test.Tester()
BEGIN
/***DO DATA AGGREGATION***/
END
"
sendQuery <- dbSendQuery(connect, query)
dbClearResult(dbListResults(connect)[[1]])
dbDisconnect(connect)