网站和平台有什么区别,wordpress 萝莉,有没有做问卷还能赚钱的网站,怎样做58网站1、前言
以前从没有试过建一张表#xff0c;不带任何列。在PG中却支持这种语法。这是个什么鬼?
最近#xff0c;把PG源码扒了下#xff0c;简单浏览了下最近的一些merge。其中有一个fix#xff1a;
eeb0ebad79 (Fix the initial sync tables with no columns.不带任何列。在PG中却支持这种语法。这是个什么鬼?
最近把PG源码扒了下简单浏览了下最近的一些merge。其中有一个fix
eeb0ebad79 (Fix the initial sync tables with no columns., 2023-11-22)Fix the initial sync tables with no columns.The copy command formed for initial sync was using parenthesis for tableswith no columns leading to syntax error. This patch avoids addingparenthesis for such tables.Reported-by: Justin GAuthor: Vignesh CReviewed-by: Peter Smith, Amit KapilaBackpatch-through: 15Discussion: http://postgr.es/m/18203-df37fe354b626670postgresql.org简单的说是它考虑到一张表在初始SYNC时有可能没有任何列。按自己的印象别的DBMS好像没有支持这种语法的。
2、简单验证
如果我们在SQLSERVER哪怕是最新版2022上试一下
https://dbfiddle.uk/1n2I7Bj9
create table tab_no_col();立马报错
Msg 102 Level 15 State 1 Line 1
Incorrect syntax near ).切到MySQL, 也不支持这种语法
https://dbfiddle.uk/xZPbFq4N
create table tab_no_col();
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ) at line 1再试下Oracle, 发现也不支持。哪怕是23C。
https://dbfiddle.uk/-F2lutlX
create table tab_no_col();
ORA-00931: missing identifier3、PostgreSQL中的行为
我们就以PostgreSQL 14为例
postgres# create table tab_no_col();
CREATE TABLE
postgres# insert into tab_no_col default values;
INSERT 0 1
postgres# select * from tab_no_col;
--
(1 row)postgres# insert into tab_no_col default values;
INSERT 0 1
postgres# insert into tab_no_col default values;
INSERT 0 1
postgres# insert into tab_no_col default values;
INSERT 0 1
postgres# select count(*) from tab_no_col;count
-------4
(1 row)postgres# select * from tab_no_col;
--
(4 rows)虽然没有真正的值但是却一样可以插入相关的值并得到相应的行数。
根据这种特性我们甚至可以预先建一张没有任何列的表然后插入一些列。看看
postgres# alter table tab_no_col add col2 varchar(32) null;
ALTER TABLEpostgres# select * from tab_no_col;col2
------(4 rows)更新一些值
postgres# update tab_no_col set col2 a_ || ctid || _ || xmin;
UPDATE 4
postgres# select * from tab_no_col;col2
-------------a_(0,1)_785a_(0,2)_786a_(0,3)_787a_(0,4)_788
(4 rows)这种功能也许最大的好处就是先建一张表空列然后可以动态的增加或改变一些列。利用FOR循环时直接( 和 ”) 做匹配而不用考虑列数是否真正大于0。
反正CREATE TABLE ABC, 即算完全是空的语法上它也不会报错。