PostgreSQL 数据类型及语句-boolean、numeric、text 字段

作者:vkvi 来源:ITPOW(原创) 日期:2021-5-11

boolean

SQL Server 是 bit,并使用 1 代表 true,0 代表 false。

PostgreSQL 直接是 boolean,使用 true、false 赋值,大小写无所谓,因为它会被转换成小写。

numeric

可用来表示精确的小数。

text

可用来表示字符串。

字符串用单引号包起来。

字符串内的单引号,需替换为 2 个单引号。

字符串连接,使用 ||。

like 查询

update tbl set username='123' where id=1;
update tbl set username='1%3' where id=2;
update tbl set username='1_3' where id=3;
update tbl set username='1\3' where id=4;
select * from tbl where username like '1\%3';
select * from tbl where username like '1\_3';
select * from tbl where username like '1\\3';

% 和 _ 都是通配符,如果要将其按普通字符对待,加 \ 即可,C# 替换语句:

s = s.Replace(@"'", @"''").Replace(@"\", @"\\").Replace(@"_", @"\_").Replace(@"%", @"\%");

支持 N 吗?比如:fld=N'ITPOW'。支持!

支持 "tbl"."fld" 这种写法吗?支持!

除了 like,PostgreSQL 还有很多有趣的查询,比如正则表达式,更多文档,请参见:PostgreSQL 13.2 Documentation

相关文章