I need to run below Sql query through a python code and get the output of it.
How can I make it work using "os" module. I can't install sql module on the system where I have to execute this query in python.
Program should run this sql query, check for the account id in database and execute the output from sql query. I havent worked with sql from long time, getting issue to understand it.
It should be something like this but something is wrong here.
import os
id = raw_input("Enter account_id:")
os.system('sql2 -q abc.dev.domain.com "select account_name, account_id, is_enrolled from (select * from my_db where account_id = '$id' and is_enrolled = check by account_name')
Related
I would like to find out which version of DB2 we are running on our IBM i server using only SQL SELECT.
I am executing my queries via installed ODBC drivers for i Access. The places I am executing the queries are Excel-ODBC and Excel-Microsoft Query (simply because I am not a developer and therefore don't have/don't know of another place to run queries).
The following solutions do not work for me:
How to check db2 version
Get DB2 instance name using SQL
Basic reasons why I have failed to get the above solutions to work:
I do not have a SYSPROC table/have access to SYSPROC table
SYSIBMADM table does not contain a ENV_INST_INFO table.
I think these answers may be tailored to those using IBM z, but I use IBM i.
My end goal is to be able to execute a SQL SELECT and get the version of DB2 used on our server.
Try this:
SELECT RELEASE_LEVEL, TEXT_DESCRIPTION
FROM QSYS2.SOFTWARE_PRODUCT_INFO
WHERE PRODUCT_ID = '5770SS1'
AND PRODUCT_OPTION = '27'
--or this instead of the above line:
--AND LOAD_TYPE = 'CODE' AND PRODUCT_OPTION = '*BASE'
I am trying to parameterize certain where clauses to standardized my Postgres SQL scripts for DB monitoring. But have not found a solution that will allow me to have the following script run successfully
variablename = "2021-04-08 00:00:00"
select * from table1
where log_date > variablename;
select * from table2
where log_date > variablename;
Ideally, I would be able to run each script separately, but being able to find/replace the variable line would go a long way for productivity.
Edit: I am currently using DBeaver to run my scripts
To do this in DBeaver I figured out you can use Dynamic Parameter Bindings feature.
https://github.com/dbeaver/dbeaver/wiki/SQL-Execution#dynamic-parameter-bindings
Here is a quick visual demo of how to use it:
https://twitter.com/dbeaver_news/status/1085222860841512960?lang=en
select * from table1
where log_date > :variablename;
When executing the query DBeaver will prompt you for the value desired and remember it when running another query.
I am doing local development for SAP CAP with Nodejs project in VSCODE. I am connected to XSA Server. I am trying to create hana database user in XSA environment. I want to first check if the list of users that my app will create is already existing or not. For that, I am trying to execute a select query with where clause. Its a prepared statement, which i am trying to execute with execBatch(array). Below is the code.
let arr = [["POC_ADMIN_DEMO_USER_7"],["POC_ADMIN_DEMO_USER_1"]]
const checkuserexiststatement = await xsaDbConn.preparePromisified("SELECT USER_NAME FROM USERS WHERE USER_NAME = ?")
let readuserresult = await checkuserexiststatement.execBatch(arr)
console.table(readuserresult)
The execution of the query fails with the following error -
Error
Error: SQL command would generate a result set at
C:\Users\Documents\XSA\SAC_POC\cap_njs\cap_njs\user_management.js.createUsers
(C:\Users\Documents\XSA\SAC_POC\cap_njs\cap_njs\user_management.js:59:60)
I want to know if select query/statement supports execBatch() functionality in Hana as the same select statement works without any placeholder that is when the value of the user_name is provided directly in the where clause and exec() used instead of execBatch(), Or is it that I am missing some point here?
execBatch() - returns no of rows affected as a result of the query executed. Select query returns a result set (if any) or else an empty array in Node.js.
Therefore execBatch() is not compatible with Select query because execBatch() is used for batch execution and selection is one shot instead of batch.
I'm running the BigQuery command line shell and I'm not able to successfully run multi-line queries (aka queries with line breaks) because whenever I paste the query into the shell each line gets run individually instead of the whole thing together.
For example,
select * from table
works fine because it is in one line but if I try to run
select
*
from
table
it does not work because each line gets run separately.
Is there any way to get this to work?
The query command creates a query job that runs the supplied SQL query. in the documentation Using the bq command-line tool you can find some examples like:
bq query --nouse_legacy_sql \
'SELECT
COUNT(*)
FROM
`bigquery-public-data`.samples.shakespeare'
Honestly I too couldn't find decent help on this, so I created a bit of a workaround using the CONCAT function. Notice that I have a space before the FROM clause. Hope his helps.
DECLARE table_name STRING DEFAULT '20220214';
DECLARE query STRING;
SET query = CONCAT("""select user_pseudo_id, user_id""",
""" FROM `app.analytics.events_""" || table_name || """` where user_id IS NOT NULL group by user_pseudo_id, user_id""");
EXECUTE IMMEDIATE query;
Suppose I want to display the result of a simple SQL query, say SELECT * FROM dual; that is executed in SQL developer and get the result in unix server using a simple command. I do not want to use scripts to get the result. Hoping to use a single line command. I already tried using the isql command, but that is not working.
echo "select * from dual" | isql -v dbname userid hostname
Please help me.