XQuery expression has an unexpected token "/" - db2

So I'm working with DB2 from command line. Before you ask, yes, it is running with admin rights and I can connect to the database and db2 is running.
Here is my input in the cmd:
db2 xquery declare default element namespace "http://tpox-benchmark.com/security"; for $s in db2-fn:xmlcolumn("SECURITY.SDOC")/Security where $s/Symbol= "BCIIPRC" return $s
And this is the error that I get:
SQL16002N An XQuery expression has unexpected token "/" following
"pace http:". Expected tokens may include: ":". Error
QName=err:XPST0003. SQLSTATE=10505

And your question is?
Your shell may be stripping away those double quotes. Try enclosing the entire xquery statement in single quotes:
db2 'xquery declare ... return $s'

I replaced the " with ' and it works now. Thanks #mustaccio for the suggestion.
db2 xquery declare default element namespace "http://tpox-benchmark.com/security"; for $s in db2-fn:xmlcolumn("SECURITY.SDOC")/Security where $s/Symbol= "BCIIPRC" return $s

Related

I want to make a copy with postgres

I want to integrate a postgres request in symfony with the statement, however I can't communicate the right path for the copy
$RAW_QUERY = 'copy data(subject,predicate,object,lang) from :text DELIMITER \';\' CSV HEADER';
$statement = $this->emi->getConnection()->prepare($RAW_QUERY);
$statement->bindValue('text', $this->params->get('kernel.project_dir') . '/imports/flux.csv');
$statement->executeStatement();
error:
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "$1"
LINE 1: copy data(subject,predicate,object,lang) from $1 DELIMITER '...
^
The COPY filename is not a substitutable parameter, and COPY itself is not a preparable command. You will have to interpolate the filename into the command and run it directly.

prevent printing exception in logs in my perl script which has original DB password

Prevent printing exception in my perl script. in Exception original DB password is being printed so i'm trying to suppress it.
I have already tried system("$sql1 &2>dev/null") but it is not help full
sub somefunc{
my sql1 = sqlplus -S $user_name/$password\#$TNSname $sqlfilename $somestring;
system(sql1);
}
Exception :
some time $somestring is coming with character like '>' and '(' so >im getting
sh: -c: line 0: syntax error near unexpected token `>'
sh: -c: line 0: `sqlplus USERNAME/RAWPASSWORD#TNSNAME >#log.sql somescript.sh >>> Start time:
Sun #Jul 21 20:33:09 CDT 2019'
In above error the RAWPASSWORD is being printed in logs so i am
trying to avoid it
The best solution is probably not to use sqlplus to access your database. you should, instead, look at DBI and DBD::Oracle.
I would suggest using qx// or IPC::Open3 but if that's not feasible try something like below:
sub somefunc {
my $sql1 = "sqlplus -S $user_name/$password\#$TNSname $sqlfilename $somestring";
my #msg = qx/$sql1 2>&1/;
}
and then read the output in #msg and action accordingly.
Must read - What's the difference between Perl's backticks, system, and exec?

HiveQL - How to use escaped keywords in a WHERE clause?

I am trying to query a table by selecting only those cases that meet a certain condition. It is a query called from Beeline, within a R script.
The problem is the field that must meet this condition has a reserved word as a column name: 'table'.
Whenever I run this in an AWS-EMR cluster:
SELECT ... FROM ... WHERE `table` = 'something' AND year = 2018
I get the following error:
bash: table: command not found
Connecting to jdbc:hive2://localhost:10000
Connected to: Apache Hive (version 2.3.2-amzn-0)
Driver: Hive JDBC (version 2.3.2-amzn-0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
. . . . . . . . . . . . . . . . Error: Error while compiling statement: FAILED: ParseException line 1:242 cannot recognize input near '=' ''something'' 'and' in expression specification (state=42000,code=40000)
Closing: 0: jdbc:hive2://localhost:10000
ExitValue: 1
Both blocks marked in bold style should be fixed. Notice that the keyword 'table' is already escaped with backticks.
I have searched the web, but still cannot find a proper solution. Any help would be appreciated.
As #SamsonScharfrichter pointed out in the comments:
Short-term workaround: try escaping back-ticks i.e. \`table\` or maybe \\`table\\`
This worked for my problem.

PostgreSQL JDBC execute PL/pgSQL

While trying to run PL/pgSQL via JDBC driver (postgresql-9.4.1211.jre7.jar; using ANT) I get following error: ERROR: syntax error at or near "$"
Is there any way howto fix this via setting JDBC properties or changing the query of PL/pgSQL?
query:
DO $$
BEGIN
CREATE SEQUENCE id_sequence_SEQ OWNED BY id_sequence.id;
EXCEPTION WHEN duplicate_table
THEN
END
$$
LANGUAGE plpgsql;
error:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$"
Position: 5
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:305)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:291)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:269)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:265)
I tried executing a DO statement with JDBC and it works just fine.
There must be something weird in your statement. Try and log the statement by setting log_min_error_statement and log_min_messages to error. Execute the statement, then look at the message in the PostgreSQL log file. It should contain the statement that was actually executed. Examine it for weird characters and other strangeness.
Please also note that there is a syntax error in you PL/pgSQL: there must be something between THEN and END. For a no-op, use the statement NULL;.

Is DB2 CLPPLUS editor able to do xquery

I am new to the CLPPlus editor and I'm trying a simple query that works if I execute it from a file like this
db2 -td% -svf C:\query.sql
and the query.sql file contains:
SELECT tx.ID,XMLQUERY('for $e in $d/Client/Address return data($e)' passing tx.contactinfo as "d") FROM clients tx %
If I just place the query as it is in the CLP or CLPPLUS editor as it is I get errors.
Error FROM CLP: SQL0104N An unexpected token "for $e in $d/Client/Ad"
was found following "LECT tx.ID,XMLQUERY(". Expected tokens may
include: "
Error from CLPPLUS: SQL16002N An XQuery expression has an unexpected
token "in" following "for ". Expected tokens may include: "is". Error
QName=err:XPST0003.