postgresql 整数数据类型的单引号插入语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32495393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:01:23  来源:igfitidea点击:

Insert statement with single quote for Integer datatype

sqlpostgresqlsql-insert

提问by user3134614

I have a table table1(idinteger, Namevarchar, Ageinteger)

我有一张表table1id整数、Namevarchar、Age整数)

While inserting rows into the table I use two statements.

在向表中插入行时,我使用了两个语句。

  1. INSERT INTO TABLE1('1','John','33');and
  2. INSERT INTO TABLE1(1,'John',33);
  1. INSERT INTO TABLE1('1','John','33');
  2. INSERT INTO TABLE1(1,'John',33);

Both of them work fine. In the first insertstatement I have used the value between single quote for the integer datatype as well.

他们两个都工作正常。在第一条insert语句中,我也将单引号之间的值用于整数数据类型。

Can I know what can be the difference between both of the statements?

我能知道这两个陈述之间有什么区别吗?

回答by Yagnesh Agola

There is no difference between using single quote for Integer datatype or not.

对 Integer 数据类型使用单引号与否没有区别。

In first case it will load db server to convert your string literal to integer data type whereas in second case it will directly store integer value to database.

在第一种情况下,它将加载数据库服务器以将您的字符串文字转换为整数数据类型,而在第二种情况下,它将直接将整数值存储到数据库中。

Its good to used without single quote, since that would just be an extra unnecessary step for the database to convert the string literal into a numeric value and also make some little bit difference in performance when there are more records inserted at a time.

不用单引号就可以很好地使用,因为这只是数据库将字符串文字转换为数值的一个额外不必要的步骤,并且在一次插入更多记录时也会使性能有所不同。