Catch sql query result in file shell - sql

I'm trying to capture the output of a sql query launched via script.
The script :
#!/bin/bash
sql articledb <<< "select toppapier from table \g \q"
The output:
INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation
Ingres Linux Version II 9.2.0 (int.lnx/143)NPTL login
Thu Aug 31 16:38:02 2017
continue
* Executing . . .
E_US0836 line 1, Column 'toppapier' not found in any specified table.
(Thu Aug 31 16:38:02 2017)
Ingres Version II 9.2.0 (int.lnx/143)NPTL logout
Thu Aug 31 16:38:02 2017
I want to redirect the output to a file and ONLY catch the error/result (here: E_US0836 line 1, Column 'toppapier' not found in any specified table.)
How may I achieve this?

The Ingres terminal monitor (sql) has some commands which would help, but I don't think these were available in 9.2.0 which is now quite elderly; it's worth checking your support position on that release.
If you're stuck on 9.2.0 and can't upgrade, I think your best bet would be to redirect output to a file and check that for errors. I usually use:
egrep "^E_[A-Z]{2}[0-9A-F]{4}"
An alternative might be to install a separate client of a later version, and use that to reach the existing 9.2.0 databases.
This would allow the use of commands within the terminal monitor to control the format of the output - such as \silent, [no]titles, \vdelim, \colformat, and \redir (useful if you want errors and query output sent to different destinations).
There's more info on those commands in the online documentation. On docs.actian.com, look for the Ingres Command Reference Guide -> Using Ingres Commands -> sql Command -> Terminal Moitor Command Summary.

Related

PostgreSQL - getting an error when listing databases with message "ERROR: column d.daticu does not exist"

what could be causing the error below when listing databases in PostgreSQL.
I have 2 clusters running on the same machine under different ports and different data directories. The command works fine when I connect to one of them but fails when I connect to the other.
One cluster is using the PostgreSQL database community version while the other is using the EnterpriseDB Advanced Server 12.1.2 postgres platform but seated on the same machine though different directories.
My psql client version is psql (EnterpriseDB) 12.1.2 and the database version is PostgreSQL 12.1, compiled by Visual C++ build 1914, 64-bit
Error being experienced is:
postgres=# \l
ERROR: column d.daticu does not exist
LINE 6: d.daticu as "ICU",
^
HINT: Perhaps you meant to reference the column "d.datacl".
Your server is open source PostgreSQL, while psql is EnterpriseDB's fork.
EnterpriseDB must have hacked up their pg_database to include an additional column, and the query run for \l references that column. Now open source PostgreSQL doesn't have that column, so the query fails.
Use psql from the same distribution as the server for best results.

SQL Schema Compare from one SQL version to another not working

In Visual Studio (2013 or 2015, they both do the same) > SQL Schema Compare, I am trying to copy the schema from one database on sql 2008, to databases on sql 2014. From 2008 -> 2008 works fine, 2014->2014 works fine, but when trying to go from 2008->2014, it does not work. After running the compare and hitting update it just sits on "Schema Compare generate script (db1 > db2) until it eventually freezes and visual studio just says it is busy, and never finishes. I can not find a log that explains what point it gets stuck on either.
Under options I have tried to ignore compatibility issues but this does not fix it. Any suggestions?
That might be a schema compare bug. I'd suggest first ensuring that you're using the latest version of the SQL Server tools (available for download here: https://msdn.microsoft.com/en-us/library/mt204009.aspx)
Then, if the problem still persists, I'd suggest capturing a trace log using the below instructions and opening a Connect issue that describes the problem and includes the trace log at https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx using the category "Developer Tools (SSDT, BIDS, etc.)"
Gathering an Event Log for SSDT
Open a new command prompt as Administrator.
Run this command logman create trace -n DacFxDebug -p "Microsoft-SQLServerDataTools" 0x800 -o "%LOCALAPPDATA%\DacFxDebug.etl" -ets
Then run this command: logman create trace -n SSDTDebug -p "Microsoft-SQLServerDataToolsVS" 0x800 -o "%LOCALAPPDATA%\SSDTDebug.etl" -ets
Run SSDT and reproduce the issue.
Go back to the command prompt and run the following commands:
logman stop DacFxDebug -ets
logman stop SSDTDebug -ets
The resulting ETL files will be located at %LOCALAPPDATA%\SSDTDebug.etl & %LOCALAPPDATA%\DacFxDebug.etl.
Instead of hitting "Update" try "Generate Script", and then run the script on the destination database.

How does one find out the version of Apache Pig programmatically?

I am using Pig through Cloudera's Hue (web interface), not through the command line. And, in fact, due to corporate restrictions, I have no access to the command line, but only to the Pig Shell itself through a the web interface.
I would like to find out my version of Apache Pig by means of some command that I can issue in the Pig language itself.
Does anybody know how to do it?
You can guess the version from the logs but if you put
--version
as a 'Pig parameter' in the properties tab in the left box it will print:
Apache Pig version 0.12.0-cdh5.3.0-SNAPSHOT (rexported) compiled Sep
29 2014, 03:12:32
Run pig script using PigRunner.run() for Pig version 0.8+ Apache Pig
version 0.12.0-cdh5.3.0-SNAPSHOT (rexported) compiled Sep 29 2014,
03:12:32
You can declare a variable in the properties file as follows:
PIG_VERSION `/home/hadoop/pig/bin/pig -version|head -n 1`
Those are backticks. Now in your script, PIG_VERSION will hold the version. In my case it holds:
Apache Pig version 0.12.0 (rexported)
A quick and dirty way to check the output is to try writing a file to 'SomeDirectory/$PIG_VERSION' and it will create a nested directory structure with each word.

Derby classpath can't connect to database

I just installed derby and I followed the instructions from here the exact same way it told me to but replacing the paths with my paths. But for some reason why i try to create a connection to connect to create a Database and run my sql scripts to create the tables and populate them it gives me a few errors firstly is this one
ERROR 08001: No suitable driver found for jdbc:derby:SuperMarket;create=true
Then when my sql scripts run I get this error
IJ ERROR: Unable to establish connection
I dont see what I did wrong this is the line i used to set the class path
C:\> set CLASSPATH=%DERBY_INSTALL%\lib\derby.jar;%DERBY_INSTALL%\lib\derbytools.jar;.
I included the derby.jar file that was needed so I can't see the problem does anyone know what I did wrong? Also when I run
connect 'jdbc:derby://localhost:1527/MyDB';
The server starts fine
C:\Derbs\db-derby-10.10.2.0-bin\bin>startNetworkServer
Thu Jun 26 11:56:38 PDT 2014 : Security manager installed using the Basic server
security policy.
Thu Jun 26 11:56:39 PDT 2014 : Apache Derby Network Server - 10.10.2.0 - (158244
6) started and ready to accept connections on port 1527
There are many troubles when I start using DerbyDB. It is really painful to practice.
1. For example, I download Derby from http://db.apache.org/derby/derby_downloads.html#Latest+Official+Releases
2. Unzip to C:\tools\db-derby-10.11.1.1-bin.
3. Press Windows key + R, type: SystemPropertiesAdvanced, set up environment variables.
Reference: https://db.apache.org/derby/docs/10.0/manuals/getstart/gspr16.html
4. Run cmd,
We should run additional command:
C:\tools\db-derby-10.11.1.1-bin\bin\NetworkServerControl.bat
and type:
C:\tools\db-derby-10.11.1.1-bin\bin\ij.bat
then press Enter, and result:
5. We will put in-memory Derby database to D:\ directory. Folder vy1 must doesn't exit. We type command for creating new database named vy1:
connect 'jdbc:derby:D:\vy1;create=true';
Use Windows Explorer, go to directory D:\vy1, you will see new folder named vy1 just created.
then type command:
connect 'D:\vy1'
6. See SQL command to create database, table, insert, then read database like this:
(Open images in new web page is better for view. Note: This is my old screenshot when I use older version few months ago).
Come back to your question, focus at section 3, and commnand call NetworkServerControl.bat at section 4.
Good luck! :)

How can I execute SQL scripts using TeamCity?

I´m new with TeamCity and I don´t know how to run SQL scripts with it.
Is the way simply selecting the path of those scripts in a Command Line Build Runner ?
I´m pretty lost.
Regards.
In a command line build step:
Command executable: c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe
Command parameters: -S <server> -i <path_to_file> <== Note: that's a capital -S!
You may need to change the 100 to something else, depending on the version of the SQL Server tools that you have installed on the build agent.
I believe that SQLCMD / SQLPLUS / MYSQL are available as standalone executables which you can install on the TeamCity server.
Microsoft® SQL Server® 2008 R2 Feature Pack
Oracle SQL Plus
MYSQL Command Line
However, without knowing your actual SQL Platform this may differ and the provider should have an alternative.
You can then create a Command Line Runner to call the executeable and pass in the parameters required, which are further explained here.
Using the sqlcmd Utility
Using sqlplus utility
If you are looking at doing Database Migrations as part of your CI process, it would also be worth checking out RoundhousE