Error ZeosLib Open Query character $ in string query - sql

When executing a query string with the $ character, example 'select id from table where fieldname = 'abc$', it is giving error , preparade statament does not exists
Zeos Lib 7.2
Postgresql 9.6

Related

How to write a DB2 Function with a Timestamp as input parameter

I try to write a function with an input like ( IN myDate DateTime) but i run into "DATETIME" ist ein nicht definierter Name.. SQLCODE=-204, SQLSTATE=42704, DRIVER=3.69.56
How can i fix it?
If you want TIMESTAMP input parameter, you should declare it as such. See an example:
$ db2 "create or replace procedure timestamp_to_month(in ts timestamp)
language sql
return month(date(ts))"
$ db2 "call timestamp_to_month(current timestamp)"
Return Status = 9
$ db2 "call timestamp_to_month(timestamp('2019-01-01'))"
Return Status = 1

Using variable in Oracle function

I have a variable and want to use in a query inside fuzzy function but it is giving me some syntax error or wrong result considering the var.
ORA-20000: Oracle Text error:
DRG-50901: text query parser syntax error on line 1, column 21 29902.
00000 - "error in executing ODCIIndexStart() routine"
When I replace the my_var variable in the fuzzy function with some static string it works fine but with variable it is giving me this error.
My query is as follows:
DEFINE my_var = 'Bhularam';
SELECT a.EXTERNALID_ENC,
a.EXTERNALID,
a.TELNUMBER,
a.TELAREACODE,
a.DQ_ENGLISH_NAME,
a.DQ_ARABIC_NAME,
a.NAMEFIELD_1,
a.USAGETYPE,
a.MANUAL_UPDATE_FLAG,
a.RULE_UPDATE_FLAG,
a.BUSINESS_UPDATE_FLAG,
a.EXCEL_UPDATE_FLAG
FROM (
SELECT * FROM (
SELECT dqlist.*,
score(1) AS rank
FROM dq_list_hash_full dqlist
WHERE contains(dqlist.dq_english_name
,'definescore(fuzzy(my_var, 1, 6, weight),relevance)',1) > 0
UNION
SELECT
dqlist.*,
score(1) AS rank
FROM
dq_list_hash_full dqlist
WHERE
contains(dqlist.dq_english_name,'!Bhularam',1) > 0
)
ORDER BY
rank DESC
) a
I know it is something really stupid but I am unable to get my head around it probably I am new to oracle. Please help me out.
If using sqlplus, verify what prefix character is used to identify substitution variables. Default is set to '&'.
sqlplus > show define
define "&" (hex 26)
Try using your substitution variable within your query, for example
sqlplus > define my_var='hello world!'
sqlplus > select '&my_var' from dual;
old 1: select '&my_var' from dual
new 1: select 'hello world!' from dual
'HELLOWORLD!'
--------------------------------
hello world!
For your query try (assuming define is set to '&'):
'definescore(fuzzy(&my_var, 1, 6, weight),relevance)',1)

Don't understand where is syntax error ? PostgreSQL 11

PostgreSQL version : 11.1
Platform : OSX Mojave 10.14.1
That's my SQL code:
COPY (select nom,prenom,num_carte,pdv_carte,email,date_naissance from compte where num_carte != '' order by id_compte) TO :export_file WITH DELIMITER AS ';' CSV FORCE QUOTE * ENCODING 'UTF-8';
That line is in a .sql file called by shell script like this :
psql --dbname=test -U postgres --set adresses=$DATA_ADRESSE --set export_file="$EXPORT_FILE" --file=$ANO_SQL 1>>$ANO_LOG
With EXPORT_FILE variable declared like that :
export EXPORT_FILE=‎⁨"'export_for_fid.csv'"
Tried many solutions but none worked, always the same syntax error:
ERROR: syntax error at or near "‎⁨"
LINE 1: ...where num_carte != '' order by id_compte) TO ‎⁨'export_for_fid.csv' WITH D...
^
Instead of using --file and --set arguments, you could use a here-document in your shell script: (NOTE: I replaced the COPY by a \COPY )
#!/bin/sh
EXPORT_FILE="export_for_fid.csv"
DB_NAME="test"
psql --dbname=${DB_NAME} -U postgres <<OMG
\COPY (select nom,prenom,num_carte,pdv_carte,email,date_naissance from compte where num_carte <> '' order by id_compte) TO '${EXPORT_FILE}' WITH DELIMITER AS ';' CSV FORCE QUOTE * ENCODING 'UTF-8';
OMG
#eof

Hive {Case..when} is not recognizing the hiveconf variable passed from shell script

I am getting below error while running hive query.
FAILED: ParseException line 36:106 cannot recognize input near '$' '{' 'hiveconf' in expression specification
Here is my requirement:
I have two roll_condition..
if roll_cond=1 then execute something
if roll_cond=2 then execute something
Trying to achieve this with the below code
INSERT OVERWRITE TABLE db.tab_name partition(yr,mon)
select xxxx,xxx,xx,xx
from db.tab_name
left join db.name
on condition
where case when ${hiveconf:roll_cond}=1 then yr = case
when ${hiveconf:refresh_yr} <> 0 then ${hiveconf:refresh_yr}
else year(current_date) end;
when ${hiveconf:roll_cond}=2 then condition end;
So when I run the script with '1' it ran fine but when I give '2' it is giving me above mentioned error.
Please suggest where the code is failing?
Thanks in advance.

Escaping special character when SQL output to variable in shell script

Trying to assign output from SQL query on an object containing special characters to a variable in shell script.
Running directly on the database:
db2 -x 'select count(*) from <SCHEMA>."/BIC/TEST"'
11000
Yet when I include this in script I need to use double quotes as I am using variables passed into the sql. Using single quotes
Output=$(db2 -x 'select count(*) from ${_SCHEMA}."/BIC/TEST"')
echo -e "$Output"
Results in:
SQL20521N Error occurred processing a conditional compilation directive near
"_". Reason code="7". SQLSTATE=428HV
When I use double quotes I hit:
SQL0104N An unexpected token "'/BIC/TEST'" was found following "ount(*)
Tried to escape the double quotes using another set of double quotes:
db2 -x 'select count(*) from ${_SCHEMA}.""/BIC/TEST""'
But this doesn't seem to work in script. It works for tables where there is no special characters/requirement to encase in quotations.
Any help is appreciated.
The code below works fine for me, notice the escaped quotes. If it fails for you, you need to give more details of your DB2-version and the DB2-server operating system platform.
#!/bin/ksh
db2 connect to sample
(($? > 0 )) && print "Failed to connect to database" && exit 1
db2 -o- "drop table \"/bin/test\" "
db2 -v "create table \"/bin/test\"(a integer)"
(($? > 0 )) && print "Create table failed" && exit 1
db2 -v "insert into \"/bin/test\"(a) values(1),(2),(3),(4)"
(($? > 0 )) && print "insert rows failed" && exit 1
db2 -v describe table \"/bin/test\"
typeset -i count_rows=$(db2 -x "select count(*) from \"/bin/test\"" )
(($? > 0 )) && print "query count rows failed" && exit 1
print "\nRow count is: ${count_rows}\n"
db2 -o- connect reset