本文介绍了如何在Postgres中创建与SQL Server的Identity列等效的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个使用MSSQL作为其后端的应用程序。现在,我正在开发代码,以便可以使用PostgreSQL。我几乎完成了它,除了执行时有一个区别:

There is an application which uses MSSQL as its back end. Now I am developing code so that it may use PostgreSQL. I have almost completed it except there is this one difference when executing:

保存新应用程序时,

SQL Server代码:

SQL Server code:

create table tower 
(
  npages integer, 
  ifnds integer, 
  ifnid integer, 
  name varchar(20), 
  towid integer not null IDENTITY
)

PostgreSQL代码:

PostgreSQL code :

create table tower 
(
  npages integer, 
  ifnds integer, 
  ifnid integer, 
  name varchar(20)
)

为什么通过PostgreSQL执行时towid字段(默认字段)没有自动生成?

Why doesn't the towid field (which is a default field) not get generated automatically when executing through PostgreSQL ?

任何可能的原因?触发器?

Any possible reason? Triggers? Procedures?

推荐答案

PostgreSQL将完全按照您的要求创建表。它不会自动生成某些列(几乎,但这是低级)。您需要在请求中添加 towid串行主键

PostgreSQL will create table exactly as you requested. It will not generate some column automatically (almost, but this is low level). You need add towid serial primary key to your request.

这篇关于如何在Postgres中创建与SQL Server的Identity列等效的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 10:27