在PostgreSQL中,name是一个特殊的关键字吗? [英] Is name a special keyword in PostgreSQL?

查看:852
本文介绍了在PostgreSQL中,name是一个特殊的关键字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ubuntu和PostgreSql 8.4.9。

I am using Ubuntu and PostgreSql 8.4.9.

现在,对于数据库中的任何表,如果我从表名中选择 select table_name.name ,它会显示一个每行的连接列的结果,尽管我在表中没有任何 name 列。对于具有名称列的表,没有问题。知道为什么吗?

Now, for any table in my database, if I do select table_name.name from table_name, it shows a result of concatenated columns for each row, although I don't have any name column in the table. For the tables which have name column, no issue. Any idea why?

我的结果是这样的:

select taggings.name from taggings limit 3;

---------------------------------------------------------------
 (1,4,84,,,PlantCategory,soil_pref_tags,"2010-03-18 00:37:55")
 (2,5,84,,,PlantCategory,soil_pref_tags,"2010-03-18 00:37:55")
 (3,6,84,,,PlantCategory,soil_pref_tags,"2010-03-18 00:37:55")
(3 rows)


select name from taggings limit 3;
ERROR:  column "name" does not exist
LINE 1: select name from taggings limit 3;


推荐答案

这是一个令人困惑的功能历史。具体来说,您可以使用表名从表中整体引用元组,然后附加 .name 将调用 name 对它们起作用(即,将其解释为从t选择名称(t))。

This is a known confusing "feature" with a bit of history. Specifically, you could refer to tuples from the table as a whole with the table name, and then appending .name would invoke the name function on them (i.e. it would be interpreted as select name(t) from t).

在PostgreSQL 9开发的某个时刻,Istr对此进行了一些清理。您仍然可以显式地从t 中选择选择t来获得按行显示行效果,但是不能以相同的方式应用函数。因此在PostgreSQL 8.4.9 上,

At some point in the PostgreSQL 9 development, Istr this was cleaned up a bit. You can still do select t from t explicitly to get the rows-as-tuples effect, but you can't apply a function in the same way. So on PostgreSQL 8.4.9, this:

create table t(id serial primary key, value text not null);
insert into t(value) values('foo');
select t.name from t;

产生奇怪的结果:

  name   
---------
 (1,foo)
(1 row)

,但在 9.1.1 上产生:

ERROR:  column t.name does not exist
LINE 1: select t.name from t;
               ^

如您所愿。

因此,要专门回答您的问题: name 是PostgreSQL中的一种标准类型(在目录中用于表名​​等),并且还有一些用于转换内容的标准函数。改为 name 类型。它实际上并没有保留,只是存在的对象调用了它,再加上一些历史古怪的语法,使事情变得混乱;开发人员已在最新版本中对此进行了修复。

So, to specifically answer your question: name is a standard type in PostgreSQL (used in the catalogue for table names etc) and also some standard functions to convert things to the name type. It's not actually reserved, just the objects that exist called that, plus some historical strange syntax, made things confusing; and this has been fixed by the developers in recent versions.

这篇关于在PostgreSQL中,name是一个特殊的关键字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆