PostgresSQL incompatible query between version 10 and 14 - sql

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;

Related

How to declare and use variable in Hive SQL?

I am using below syntax to declare and use variable in hive sql query. But it gives me an error as below
SET aa='10';
SELECT
col1 as data,
${aa} as myVar from myTable;
ERROR:
org.apache.hive.service.cli.HiveSQLException: Error while processing statement: Cannot modify aa at runtime. It is not in list of params that are allowed to be modified at runtime
I have also tried using hiveconf
SELECT ${hiveconf:aa} from myTable;
You can not pass variable like that. You need to use --hivevar. You can create a hql file with below script - hiveqry.hql. Pls note you can use either a normal variable or with hivevar keyword.
select * from ${hivevar:aa};
select * from ${aa};
Then call that script like below
beeline --hivevar table=myTable --hivevar aa=100 -f hiveqry.hql
Depending on Hive version, when you are setting variable without explicitly specifying the namespace (hiveconf or hivevar), it may work with hiveconf as a default namespace or may not work.
BTW this works in Hive 1.2:
SET aa='10';
SELECT ${hiveconf:aa};
If you specify the namespace explicitly when setting variable, it will work with both hivevar and hiveconf
Works:
SET hivevar:aa='10';
SELECT ${hivevar:aa};
Also works:
SET hiveconf:aa='10';
SELECT ${hiveconf:aa};
Does not work:
SET aa='10';
SELECT ${hivevar:aa} as myvar;
Also if above commands do not work, check if variable substitution is enabled (default is true):
set hive.variable.substitute=true;
If set to false, substitution does not work.
Read the documentation: LanguageManual VariableSubstitution

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

Hiveconf/hivevar: possible to have a dot ('.') in a variable name?

Is it possible to use a dot in a name of hiveconf variable?
All examples in a documentation show simple variable names like a.
If yes:
How do I reference it in HQL script? select ${hiveconf:airflow.ctx.dag.dag_id} as dag_id; produces syntax error (while ${hiveconf:abcd} is ok).
If no:
Why does airflow or azkaban pass variables to hive scripts like this? Wouldn't the authors know that it's not possible to reference these variables?
hive -hiveconf airflow.ctx.dag.dag_id=video-plays-adverts -f test-hiveconf.hql
Thanks!
Have checked, this works:
set hiveconf:airflow.ctx.dag.dag_id=abc;
hive> select '${hiveconf:airflow.ctx.dag.dag_id}';
OK
abc
Time taken: 0.212 seconds, Fetched: 1 row(s)
Probably you forgot about quotes.
It turns out there were several compound problems:
1) Hivevars work as a C macro system - when you assign set a = concat('-', ${hiveconf:var_name}), content of ${hiveconf:a} isn't a string, but really a command concat('-', ${hiveconf:var_name}) which gets evaluated every time you use it.
2) I was using it in static partitions, which only accept literals, so this:
INSERT OVERWRITE TABLE xyz
PARTITION (year=${hiveconf:y}, month=${hiveconf:m}, week=${hiveconf:w}, day=${hiveconf:d})
got translated to this:
INSERT OVERWRITE TABLE xyz
PARTITION (year=<complex expression>, month=<complex expression>, week=<complex expression>, day=<complex expression>)
Which is not supported - static partition need literals.
End of story. Seems like there is no way to use 'computed' (set a = concat(${b}, ${c})) hiveconf variables in places of constant.

Why is this SQL Update failing ("column name is not valid")?

I've got a SQL Server CE table like so:
...and I'm trying to update its solitary record like so:
update workTables
set fileType = "INV"
Yet I get:
Why?
UPDATE
Please see a related question here
Here check Microsoft support for yor error.
http://support.microsoft.com/kb/825392
This is from the site:
SYMPTOMS:
When you run a query on a Microsoft SQL Server 2000 Windows CE Edition version 2.0 database, and the query has a column that contains one or more space characters, the query may not be successful. Additionally, you may receive the following error message:
FAILED: select <Column Name> from <Table Name>
Error: 0x80040e14 DB_E_ERRORSINCOMMAND
Native Error: (25503)
Description: The column name is not valid. [,,,Node name (if any),Column name,]
Interface defining error: IID_ICommand
Param. 0: 0
Param. 1: 0
Param. 2: 0
Param. 3:
Param. 4: col1
Param. 5:
RESOLUTION:
To resolve this problem, enclose the column name that contains spaces in quotation marks (" "), and then run the query. For example, you can run the following query, and the query results are displayed successfully:
SELECT "col1 " FROM testtable
Your query should be:
update [workTables]
set [fileType] = 'INV'
Note: single quotes ^^^^

Firebird 1.5 : How to get the logarithm of a number

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.