Firebird 1.5 : How to get the logarithm of a number - sql

We are using Firebird 1.5 database. we need to calculate the logarithm of a number in the query, how can we do that?
I have tried :
LOG(3, number_field)
but got an error :
Error: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -804
Function unknown
LOG
SQLState: 42000
ErrorCode: 335544569
thanks for the help.

In Firebird 1.5 Log function provided via exterbal library ib_udf.dll. Check that the file is in the UDF subfoler and run a SQL command:
DECLARE EXTERNAL FUNCTION log
DOUBLE PRECISION, DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'IB_UDF_log' MODULE_NAME 'ib_udf';
There is ib_udf.sql file in the UDF subfolder which contains commands for declaration of all functions in the library.
Also consider to upgrade your database to Firebird 2.5 version where Log function is built in.

You need to use function from ib_udf library.
First you must to declare function. Look to udf/ib_udf.sql file in firebird folder.

Related

PostgresSQL incompatible query between version 10 and 14

I have the following statement, which runs fine on PostgresSQL version 10
LINE 1: UPDATE tablename SET "cliPrefix"=encode(digest(gen_random_uuid()::text, 'sha512'), 'hex');
^
But on PostgresSQL version 14 this line gave me the error:
No function matches the given name and argument types. You might need to add explicit type casts
How to fix this?
Check if exists the required extension (pgcrypto)
select * from pg_extension;
if not
create extension pgcrypto;

When trying to get the source of a function in Postgres using psql, what does the error "column p.proisagg does not exist" mean?

Background:
using postgres 11 on RDS, interface is psql on a Centos 7 box; objective is to show the source of certain stored procs / functions so that I can work with them
Problem description : When I attempt to list / show the source of a given stored function using the \df+ command which I understand to be correct for this use based on [official docs here](https://www.postgresql.org/docs/current/app-psql.html], an error is given as shown:
psql=> \df+ schema_foo.proc_bar;
ERROR: column p.proisagg does not exist
LINE 6: WHEN p.proisagg THEN 'agg'
I have no clue how to interpret this; the function in question does not contain the snippet of logic shown in the error, nor the column referenced there p.proisagg. I have verified this by opening the function in vim with \ef.
My guess based on several unrelated github issues that mention this same error for example is that it is in reference to some schema code internal to postgres.
Summary: in short, I can view the source of the functions using \ef, so my work is not impaired from a practical standpoint, however I wish to understand this error and why I'm encountering it with \df+.
I had the same issue and ran these 2 commands to fix it
sed -i "s/NOT pp.proisagg/pp.prokind='f'/g" /usr/share/phpPgAdmin/classes/database/Postgres.php
sed -i "s/NOT p.proisagg/p.prokind='f'/g" /usr/share/phpPgAdmin/classes/database/Postgres.php

How can we replace value of hive variables to check for any errors

We have a query in which we have defined more than 50 variables.
we call this hql via shell script, most of the times i get into syntax issue where i have not defined hive variables properly in the query.
Example
set hive var0=value0;
set hive var1=value1;
set hive var2=value2;
select * from ${hiveconf:var0} where col1=${hiveconf:var1} and col2=${hiveconf:var2};
I want to to check the above query result after replacing hive variables,
So is there a way to check if the variables are parsed in the right way or are there any syntax errors.
Please let me know for any alternatives as well.
Better use hivevar namespace for the same.
You can print all variable using ! echo command:
set hivevar:var0=value0;
hive> ! echo Variable hivevar:var0 is ${hivevar:var0};
Result:
Variable hivevar:var0 is value0
Also use explain extended <query> - it will print detailed query plan with predicates and fail if it is syntax error.
Update:
Also you can use SELECT for doing the same and Hive can execute simple queries without MR started if hive.fetch.task.conversion is set to more or minimal. If you are using Qubole, add also limit 1 to the query:
set hive.fetch.task.conversion=more;
select 'Variable hivevar:var0 is', '${hivevar:var0}' limit 1;
Why you may need to do this using SELECT? For example for easy checking parameter using casting or some UDF. If you need to check if parameter is of type DATE, use
set hive.fetch.task.conversion=more;
select 'Variable hivevar:var0 is', date '${hivevar:var0}' limit 1;
In this case if ${hivevar:var0} is not date, then type cast exception will be thrown and script execution terminated.
along with hivevar namespace, we can use one more property hive.root.logger=INFO,console.
this will display the query after replacing the variable value, from which we can find out the issue.
cat test.hql
set hivevar:var1=${hivevar:var11};
set hivevar:var2=2345;
select ${hivevar:var11};
select ${hivevar:var2};
hive command - hive --hiveconf hive.root.logger=INFO,console --hivevar var11=1234 -f test.hql
output on console
select 1234
2018-10-17T08:23:31,632 INFO [main] ql.Driver: Completed executing command(queryId=-4dd6-493f-88be-03810f847fe7); Time taken: 0.003 seconds
OK
2018-10-17T08:23:31,632 INFO [main] ql.Driver: OK
2018-10-17T08:23:31,670 INFO [main] io.NullRowsInputFormat$NullRowsRecordReader: Using null rows input format
1234

Db2: How to deploy an Oracle PL/SQL package in db2?

I tried to create an Oracle PL/SQL package in Db2, but ran into errors.
CREATE OR REPLACE PACKAGE ARITHMETIC AS
function add (
first number,
second number)
return number;
END ARITHMETIC;
CREATE OR REPLACE PACKAGE BODY ARITHMETIC AS
function add(
first number,
second number)
return number AS
BEGIN
return first + second;
END add;
END ARITHMETIC;
When I run the above code, it results in the following error:
Deploy [tnbdr]DB2INST1.ARITHMETIC Running
DB2INST1.ARITHMETIC - Deploy for debug started.
Create PL/SQL Package Specification returns SQLCODE: -104, SQLSTATE: 42601.
DB2INST1.ARITHMETIC: 1: An unexpected token "PACKAGE" was found
following "CREATE OR REPLACE ". Expected tokens may include:
"VIEW".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.18.60
An unexpected token "PACKAGE" was found following "CREATE OR REPLACE ". Expected tokens may include: "VIEW".. SQLCODE=-104,
SQLSTATE=42601, DRIVER=4.18.60
DB2INST1.ARITHMETIC - Deploy for debug failed.
DB2INST1.ARITHMETIC - Roll back completed successfully.
How can I deploy the package, why is it failing?
Db2 supports the compilation / creation of PL/SQL packages when the database is set up for Oracle compatibility:
db2set DB2_COMPATIBILITY_VECTOR=ORA
db2stop
db2start
Bit 12 in the DB2_COMPATIBILITY_VECTOR enables PL/SQL compilation.

How to generate executable TPC-DS queries?

I have downloaded the DSGEN tool from the TPC-DS web site and already generated the tables and loaded the data into Oracle XE.
I am using the following command to generate the SQL statements :
dsqgen -input ..\query_templates\templates.lst -directory ..\query_templates -dialect oracle -scale 1
However, No matter how I adjust the command I always get this error message :
ERROR: A query template list must be supplied using the INPUT option
Can anybody help?
Apparently you need to use / rather than - for the flags for the Windows executable:
dsqgen /input ..\query_templates\templates.lst /directory ..\query_templates
/dialect oracle /scale 1