postgres treat null as empty string when concatenated with string - enterprisedb

When I fire below query on one of our servers
select null || 'query' ,'|',version
the result is null nothing is displayed
when i fire the same query on another server which has same version of postgresql server
I am getting result as
query
postgres version on both servers are
EnterpriseDB 9.2.1.3 on i686-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 32-bit
EnterpriseDB 9.2.1.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 64-bit
Why this different behavior?

Check the setting of edb_redwood_strings parameter on both servers.
See more Oracle Compatible Configuration Parameters
edb_redwood_strings – Equates NULL to an empty string for purposes of string concatenation operations. For Oracle compatible behavior, set edb_redwood_strings to TRUE.
SET edb_redwood_strings TO off; -- or on

Related

DB2 ODBC converting NULL floats and ints to ~0

Querying DB2 from python using ODBC, I am seeing NULL values converted to 0 (on Linux, seemingly corrupt but close to 0 on Mac M1 -- even more worryingly).
This is using the db2 docker image started like this:
docker run -itd --name db2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=xxxxx -e DBNAME=testdb -v <db storage dir>:/database ibmcom/db2
Code as follows recreates the issue:
import pyodbc
cs = "Driver={ODBC Driver v11.5.7 for DB2};Database=xxxxx;Hostname=xxxx;Port=50000;Protocol=TCPIP;Uid=xxxx;Pwd=xxxx;"
cnxn = pyodbc.connect(cs)
crsr = cnxn.cursor()
crsr.execute("SELECT CAST(NULL AS INT), CAST(NULL AS REAL) FROM SYSIBM.SYSDUMMY1");
print(crsr.messages)
print(crsr.fetchall())
Outputs:
❯ python float-test.py
[]
[(2, 4.2439915814e-314)]
Is it expected that I can't retrieve NULL values as plain data types? It seems to be allowed in PostgreSQL. I know I can cast around this but would rather not, obviously.
Extra Info
It does seem that the ODBC driver version 11.5.7 from Fix Central suffers this issue whilst the 11.5.6 version from https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli does not.
As mentioned in comments, it appears pyodbc is impacted and both plain ibm_db and DBI are not impacted (both return None, None). So at least there is a workaround.
The reason for the behaviour deifference is that pyodbc is using SQLGetData() while the other two use the SQLBindCol() methods of extracting the result set data.
IBM's clidriver on Linux x64, SQLGetData() sets the (SQLLEN *) StrLen_Or_IndPtr parameter to SQL_NULL_DATA when the value of the column in result-set is NULL. But the problem is that IBMs clidrver sets StrLen_or_IndPtr to SQL_NULL_DATA (as int, 4 bytes), when pyodbc code expects it to SQL_NULL_DATA (as SQLLEN, 8bytes on Linux x64) as SQLLEN is the documented datatype for the StrLen_or_IndPtr argument.
Therefore the comparison in pyodbc getdata.cpp GetDataDouble() :
if ( cbFetched == SQL_NULL_DATA )
Py_RETURN_NONE;
will be false, causing the code to return an unitialised variable instead of Py_None.
I do not know if the maintainers of pyodbc run their tests against a Db2-LUW product, but it looks like other parts of the code could suffer the same problem and other issues may lurk. Consider asking on github what is the support policy for Db2-LUW in pyodbc.
If you have a support contract, IBM should also be asked to comment on their reason for not respecting the datatype of StrLen_Or_IndPtr when writing SQL_NULL_DATA to this parameter on Linux x64.

perldoc: 'ŷ' output as 'X' with "=encoding utf8"

When writing POD documentation, I realized that Unicode character ŷ became X on output.
Input:
=pod
=encoding utf8
=over
=item I<yt> (ŷ(t))
The value predicted for time I<t>.
=back
Output in PuTTY:
Input in Emacs:
Version of perldoc being used that of Perl 5.18.2 (SLES12 SP4, perl-5.18.2-12.20.1.x86_64), and LANG=en_US.UTF-8.
Update:
It seems to be a bug in Perl or in the package of SLES12 SP4: Using the same test on OpenSUSE Leap 15.1 with Perl 5.26.1, the output looks OK:
yt (ŷ(t))
The value predicted for time t.
However using pod2man from perl-5.26.1-15.87.x86_64 of openSUSE Leap 15.3, the output is not correct.
OTOH using perldoc the output is correct, too.

#1064 - You have an error in your SQL syntax in phpMyadmin

I built the following Query, for MySQL, on Maria Db, phpMyAdmin Ver: 4.8.3
Database server
Server: 127.0.0.1 via TCP/IP
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.1.36-MariaDB - mariadb.org binary distribution
Protocol version: 10
Web server
Apache/2.4.34 (Win32) OpenSSL/1.1.0i PHP/7.2.10
Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $
PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
PHP version: 7.2.10
SQL
SELECT tblhoadon.MaHoaDon,
tblkhachhang.HoVaTen,
tblphongtro.MaSoPhong,
tblphongtro.GiaThue,
tbldichvu.MaDichVu,
tblchitietdv.TenChiPhi,
tblchitietdv.ThanhTien,
tblhoadon.TongTien
FROM tblhoadon,
tblphongtro,
tbldichvu,
tblchitietdv
WHERE tblhoadon.MaKhachHang = tblkhachhang.MaKhachHang,
tblhoadon.MaSoPhong = tblphongtro.MaSoPhong,
tblhoadon.MaDichVu = tbldichvu.MaDichVu,
tbldichvu.MaDichVu = tblchitietdv.MaDichVu LIKE 10040001
Report error
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
near ' tblhoadon.MaSoPhong = tblphongtro.MaSoPhong, tblhoadon.MaDichVu
= tbldichvu.MaD' at line 1
Can you help me fix syntax error?
You can't just have a series of conditions. You need some logical operator between them, such as and or or.
Additionally, the last condition has several issues:
like` should take a string argument, not a number
You can't chain equalities like that, you should create two conditions with a logical and operator between them.
While it's not strictly wrong to use like without a wildcard, it's a bit pointless, and you can just use an = condition:
SELECT tblhoadon.MaHoaDon,
tblkhachhang.HoVaTen,
tblphongtro.MaSoPhong,
tblphongtro.GiaThue,
tbldichvu.MaDichVu,
tblchitietdv.TenChiPhi,
tblchitietdv.ThanhTien,
tblhoadon.TongTien
FROM tblhoadon,
tblphongtro,
tbldichvu,
tblchitietdv
WHERE tblhoadon.MaKhachHang = tblkhachhang.MaKhachHang AND
tblhoadon.MaSoPhong = tblphongtro.MaSoPhong AND
tblhoadon.MaDichVu = tbldichvu.MaDichVu AND
tbldichvu.MaDichVu = tblchitietdv.MaDichVu AND
tblchitiedv.MaDichVu = '10040001'

Postgres 9.5 cache lookup failed

I am trying to install pg_trgm into postgres (Using postgres 9.5 on ubuntu 16) by doing CREATE EXTENSION pg_trgm. The first executable line of pg_trgm--1.1.sql is
CREATE FUNCTION set_limit(float4)
RETURNS float4
AS 'MODULEPATH_NAME'
LANGUAGE C STRICT VOLATILE;
Running this line in psql or starting psql with psql -f pg_trgm--1.1.sql throws error ERROR: cache lookup failed for function 1. Any idea why this might be happening. I also tried
CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
which works fine. Do I have to install something to create sql functions using C language? I already installed contrib for postgres using sudo apt-get install postgresql-contrib

Set param from sql command in spite oracle is down

I have Solaris machine with oracle Release 10.2.0.4.0
I have problem - I cant startup oracle
when I try to start oracle by the command:
hagrp -online oracle1 -sys machine1a
I get:
oracle1 machine1a Y N PARTIAL|FAULTED
remark ( hagrp -clear oracle1 -sys machine1a not help )
After checking and debug the problem I find that oracle not start up
because wrong param - shared_pool_size (this param was set to 0 , while need to set this param to 2G)
So I want to set the param shared_pool_size to 2G but I can’t because oracle is down !!!
My question - how to set the parameter shared_pool_size to 2G in spite oracle is down ??? , is it possible ???
su - oracle -c "sqlplus / as sysdba"
SQL*Plus: Release 10.2.0.4.0 - Production on Mon Mar 5 12:10:44 2012
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter system set shared_pool_size=2G scope=BOTH;
init.ora: (from my machine)
grep shared_pool_size /opt/oracle/v10.2.0/srvm/admin/init.ora
#shared_pool_size = 52428800 # INITIAL
shared_pool_size = 67108864 # datewarehouse, transaction processing
If you were starting from an old-style init.ora parameter file you could just change it in that. The scope in your alter system suggests you're using an spfile. You can startup nomount to make parameter changes, then shutdown again and try to start normally.
Are you sure you're connecting to the right database though? The output from your sqlplus command doesn't say connected to an idle instance, so it looks like whatever you're connected to is already running. Check where you are before running anything, and note any parameters you change first (e.g. with output from show parameters).
Based on conversation in chat...
You can create a temporary pfile, edit that and test starting up with it, and then when happy with the new configuration recreate your spfile, and finally restart from that. The steps are:
create pfile='/tmp/init.ora' from spfile;
-- edit /tmp/init.ora and change parms as needed
startup pfile='/tmp/init.ora';
-- repeat as needed until successful start
create spfile=’/path/to/spfile.ora’ from pfile=’/tmp/init.ora’;
shutdown
startup 'spfile=/path/to/spfile.ora';