398 Star 1.3K Fork 1.5K

GVPopenGauss / openGauss-server

 / 详情

内置函数quote_literal针对传入的空字符串,返回结果和PG不一致

已完成
缺陷
创建于  
2020-07-25 09:44

Is this a BUG REPORT or FEATURE REQUEST?:

Uncomment only one, leave it on its own line:

  • bug

What happened:
opengauss

postgres=# select quote_literal('');
 quote_literal
---------------

(1 row)

What you expected to happen:
pg11, pg9.2

postgres=# select quote_literal('');
 quote_literal
---------------
 ''
(1 row)

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Version:
  • OS (e.g. from /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:

评论 (5)

nwen 创建了缺陷
nwen 关联仓库设置为openGauss/openGauss-server
展开全部操作日志

Hey @nwen, Welcome to openGauss Community.
All of the projects in openGauss Community are maintained by @opengauss-bot.
That means the developers can comment below every pull request or issue to trigger Bot Commands.
Please follow instructions at https://gitee.com/opengauss/community/blob/master/contributors/command.en.md to find the details.

nwen 修改了描述
nwen 修改了描述
opengauss-bot 添加了
 
kind/bug
标签

opengauss中默认认为空和NULL一样,自动将‘’转化为NULL处理,该功能由参数sql_compatibility控制,但是pg默认认为是不相等的,在语法解析的时候不一样,因此显示不一样,语法解析如下
static Node *
makeStringConst(char *str, int location)
{
A_Const *n = makeNode(A_Const);

if (u_sess->attr.attr_sql.sql_compatibility == A_FORMAT)
{
	if (NULL == str || 0 == strlen(str))
	{
		n->val.type = T_Null;
		n->val.val.str = str;
		n->location = location;
	}
	else
	{
		n->val.type = T_String;
		n->val.val.str = str;
		n->location = location;
	}
}
else
{
	n->val.type = T_String;
	n->val.val.str = str;
	n->location = location;
}

return (Node *)n;

}
测试结果如下
postgres=# show sql_compatibility;
sql_compatibility

A
(1 row)

postgres=# create table test11(a text);
CREATE TABLE
postgres=# insert into test11 values('');
INSERT 0 1
postgres=# select * from test11 where a is null;
a

(1 row)

postgres=# select * from test11 where a = '';
a

(0 rows)

hey @nwen could you help to recheck the commentf from @陈雁飞
Thanks very much.

xiangxinyong 添加了
 
question
标签
postgres=# create database pg_type_databse dbcompatibility 'PG';
CREATE DATABASE
postgres=#
postgres=# \c pg_type_databse
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "pg_type_databse" as user "omm".
pg_type_databse=# show sql_compatibility;
 sql_compatibility
-------------------
 PG
(1 row)

pg_type_databse=# select quote_literal('');
 quote_literal
---------------
 ''
(1 row)

pg_type_databse=#

社区在最新版本代码中可以创建PG数据库兼容, 这样结果就跟PostgreSql的一样了
相应pr为: !91:pgdb compatibility support

蒲甫安 任务状态待办的 修改为已确认
zhangxubo 任务状态已确认 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(5)
5622128 opengauss bot 1581905080 5227357 xiangxinyong 1578982846 5353117 xixicat 1589531730
C++
1
https://gitee.com/opengauss/openGauss-server.git
git@gitee.com:opengauss/openGauss-server.git
opengauss
openGauss-server
openGauss-server

搜索帮助