I want to load and execute a sql file from another sql file, but do not the syntax. Is this possible? In detail, I have a file install_tables.sql which should load a file tables_definition.sql.
If you run your script using psql you can embedd the \i command in your main script:
\i tables_defininition.sql
Related
I am currently working on PostgreSQL (Bitnami) docker container an I am unable to execute a db script which is in .sql format from \i file-path command in psql. I searched many times but I could not find an answer for this. The PostgreSQL version is 10.12.0.
The .sql file you want to \i include must be in the Docker container, not on your machine.
Late but for posterity, if you are still facing problems after relocating your file to your docker container (or running postgres/psql from your local m/c), another thing you can check for is your file path (remove spaces).
yourdb-#\i path/to/dest/with/no/filename/spaces/script.sql;
ought to do it.
I am experiencing issues with running this psql script on ubuntu terminal to map the mimic3 database to omop common data model, the code used is
psql "mimic3" --set=OMOP_SCHEMA="$OMOP_SCHEMA" -f "mimic-omop/etl/etl.sql"
the code stops running at the last truncate table command where it should call this sql script titled pg_function but it gives this error:
psql:mimic-omop/etl/etl.sql:28: etl/pg_function.sql: No such file or directory
I have attached a section of the sql file below as proof that it really exists:
The last part of the query has this code where it calls all the sql files listed in my screenshot below:
I am following the instructions in this link:https://github.com/MIT-LCP/mimic-omop/blob/master/README-run-etl.md
I have a script in a file (mysqlscript.sql) that is basically a bunch of inserts/updates/deletes separated by GO statements
insert into ....
GO
update .....
GO
How do I run this script?
You can try to use $system.SQL.ImportDir()
And of course, you can read your file and execute each sql-query in your programm.
The tool Caché Monitor use GO as statement separator and connects to InterSystems Caché. With this tool you can execute your script.
I have a bunch of SQL scripts (with shell script wrappers) to unload data like so
EXPORT TO /tmp/out.csv OF DEL MODIFIED BY NOCHARDEL COLDEL, DATESISO
MESSAGES /tmp/out.msg SELECT WIDGETID
...
I want to add an error handler to the script the way Oracle does it:
WHENEVER SQLERROR EXIT FAILURE;
SPOOL /tmp/out.csv;
SELECT WIDGETID...
SPOOL OFF;
According to DB2's documentation, this can be done in stored procedures, C, Perl, REXX, and nothing else...
How can this be done in SQL scripts?
I am running DB2/LINUXX8664 9.7.2.
you could use the DB2 command line command processor and get its return code. http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.admin.cmd.doc/doc/r0010411.html
or you could use the SYSPROC.ADMIN_CMD procedure and use its return codes. http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.sql.rtn.doc/doc/r0023573.html
you could put the stored proc calls in a script file and run something like db2 -tvf runexport.txt or put the db2 commands in a linux script file and use linux scripting foo to handle the db2 return codes.
In linux I can do something like this:
mysql -u user -p=pass somedb <(echo "create database foo;")
How can I do that with windows batch scripts?
Basically, I want to make a batch file that runs a sql script without having to keep the script in a separate file.
Thanks
One way is to echo the SQL commands into a file, run the mysql command with option to include the SQL file, and then remove the file (if you really don't want it.)
You can do
echo create database foo;|mysql ...
just fine, but for multiple lines you really want to make a temporary file you just pass to MySQL to read.