Is there a way to call the psql function without syntax error calls on ubuntu when calling multiple sql files in a directory? - postgresql

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

Related

I'm trying to import a SQL backup file but I keep getting an error

I'm trying to import a SQL backup file but I keep getting the error
todolist-# psql todolist < C:\Users\ojadi\Documents\todolist2.sql
invalid command \Users
Try \? for help.
todolist-#
That is a command you give in UNIX shell, not a command you give in psql. Since it seems you already have psql running, you can run the file using command
\i C:\Users\ojadi\Documents\todolist2.sql
Note that your prompt todolist-# indicates you are in the middle of writing a command in psql. See my answer to this earlier question

Using Postgres "copy" command in Talend to load table content into CSV file

I have to copy few postgres table contents into a CSV file for further processing using Talend.
When I tried
copy table_name to ‘/tmp/export/table_name.csv’ with CSV;
with 'tpostgresqlRow' component, it threw error saying "Need superuser access", which I wouldn't be getting.
As an alternative, I tried "\copy" command as
\\copy table_name to ‘/tmp/export/table_name.csv’ with CSV;"
(first slash is used to escape the other). Still it threw error saying "Syntax error at '\'".
I tried with tpostgresqlBulkExec component as well, which internally uses "copy" command, and it as well threw error saying "Need superuser access".
Is there a way out to execute this postgres "copy" command in bulk using Talend?
Any help would be much appreciated.
The copy command needs access to both the postgres table and the local file system.
I think your problem is caused because you do not have access to the local folder. you need to sort that out, or try a different folder that you know you have access to.
with the same user, if you try linux command
touch /tmp/export/test.csv
you may see an error.
the \copy command will fail because to use that you first need to be using a tool called psql.
I got confirmation from Talend Support Team that tPostgresqlRow component would not support 'COPY' command. I have resolved my case by installing PSQL client and calling the same using tSSH component in Talend to execute the desired 'COPY' commands.

PostgreSQL COPY FROM PROGRAM using ImageMagick

I have 1000 images, and thanks to ImageMagick I can retrieve a lot of information regarding an image by writing "identify -verbose [PATH OF IMAGE]" in the cmd.
I installed ImageMagick with 'legacy on' , to access individual tools rather than the monolithic version of the library.
If I write "identify -verbose C:\\temp\\cbirCorel10k\\1.jpg" in the command prompt it works perfectly, outputting data I need.
My problem is when I insert this code into PROGRAM of PostgreSQL like so :
copy manyline(txt)
from program 'identify -verbose C:\\temp\\cbirCorel10k\\1.jpg'
It gives me this error, and please note that I do have permissions on the image and parent folders to be accessed:
ERROR: program "identify -verbose C:\temp\cbirCorel10k\1.jpg"
failed SQL state: 38000 Detail: child process exited with exit code
1
I want that the output from that command line, is inputted into the table 'manyline' under column 'txt'.
Please note that the following code works well, but I want to make use of the PROGRAM function.
copy manyline(txt)
from 'C:\\temp\\something.txt'
The postgresql server needs permissions to run that program and read that file. it usually runs under username postgres (unless they've changed that recently). this is a "service user" and can be hard to find in the windows GUI; especially on "home" editions of windows. I can't say for sure if granting NETWORK SERVICE access is enough.
easiest solution is to use the psql command-line interface and do
\copy manyline(txt) from program 'identify -verbose C:\\temp\\cbirCorel10k\\1.jpg'
\copy is a psql built-in which runs the command (opens the file etc) as the current user, instead of asking the server to run it. this also works well where the server is not local.

PostgreSQL copy 0?

I have written a simple batch script which loops a directory and echoes some details about each file.When I view its results in the CMD terminal or output it to some file, I can view the results as expected.
The problem comes with PostgreSQL: when I try to import its results into a table, executing the following command:
copy schema.table(field) from program 'C:\\...\\my_bat.bat' with CSV header delimiter E'\t';
It imports 0 results, whereas if I run the same command pointing to a similar batch file in another directory, it works as expected.
What's going on? I am using windows.
Update: I have tried running the copy command calling program again on another batch script and this time, only a part of the string output is being imported.
The service user postgres needs sufficient permissions to run the program.
I remember that it was hard to change settings for that account on windows XP, I have not tried on more recent windows - service users are hidden by most GUI tools.

DB2 executing a Script in another Script

I am facing a problem in DB2. In my Oracle environment it was very easy for me to include multiple scripts in one master script, which were executed sequentially. e.g.:
Master.sql:
connect ....
#script1.sql
#script2.sql
Now I have to build up same logic in DB2 LUW. Is there a simple way to include multiple scripts in one master script? I would like to have one single db2 call from shell, which executes the master script and within all subscripts.
Regards
Jan
There is notrhing to stop you from creating a single file with multiple sql batches. In the Windows world, it would look like this:
Note: First you initialize the db2 command prompt.
db2cmd -c -w -i %1.bat
With as many of these as you want in the .bat file:
db2 -txf c:\Example\db2html.sql
In Linux, the db2clp is included in the shell once you load the db2profile ('. /home/db2inst1/sqllib/db2profile). In windows, you need to call db2cmd in order to use db2clp.
With a interactive db2clp, you cannot call db2 scripts via #scriptX, however, you can call them from the shell like
db2 -tvf script
However, if you use the CLP*Plus you can do almost everything you do in SQL*Plus. For more information: https://www.ibm.com/developerworks/community/blogs/IMSupport/entry/tech_tip_db2_s_new_clp_plus_utility?lang=en