在新列中创建序列号
Create serial numbers in a new column
在 postgres 中,我们可以添加一个新的增量列,例如:
ALTER TABLE <table_name>
ADD IF NOT EXISTS <column_name> SERIAL;
这会在 table 中创建带有序列号的新列。在雪花中,当我尝试相同的命令时,它抛出一个错误
SQL compilation error: Unsupported data type 'SERIAL'.
如何在 Snowflake 中实现相同的行为?
SERIAL 伪类型是一个自动递增的整数,存储大小为四个字节,范围为 1 到 2,147,483,647。
您可以使用 AUTOINCREMENT 或 IDENTITY 来获得相同的功能:
create or replace table test ( id number AUTOINCREMENT, v varchar ) ;
insert into test (v) values ('Test1'),('Test2'),('Test3');
select * from test;
+----+-------+
| ID | V |
+----+-------+
| 1 | Test1 |
| 2 | Test2 |
| 3 | Test3 |
+----+-------+
PS: 无法在创建 table.
后添加这样的列
在 postgres 中,我们可以添加一个新的增量列,例如:
ALTER TABLE <table_name>
ADD IF NOT EXISTS <column_name> SERIAL;
这会在 table 中创建带有序列号的新列。在雪花中,当我尝试相同的命令时,它抛出一个错误
SQL compilation error: Unsupported data type 'SERIAL'.
如何在 Snowflake 中实现相同的行为?
SERIAL 伪类型是一个自动递增的整数,存储大小为四个字节,范围为 1 到 2,147,483,647。
您可以使用 AUTOINCREMENT 或 IDENTITY 来获得相同的功能:
create or replace table test ( id number AUTOINCREMENT, v varchar ) ;
insert into test (v) values ('Test1'),('Test2'),('Test3');
select * from test;
+----+-------+
| ID | V |
+----+-------+
| 1 | Test1 |
| 2 | Test2 |
| 3 | Test3 |
+----+-------+
PS: 无法在创建 table.
后添加这样的列