gpt4 book ai didi

postgresql - postgresql中从表名中选择属性名(表名)是什么意思

转载 作者:行者123 更新时间:2023-12-04 07:53:00 25 4
gpt4 key购买 nike

使用 Postgresql 我有一个我不明白的明显奇怪的行为
假设有一个简单的表

create table employee (
number int primary key,
surname varchar(20) not null,
name varchar(20) not null);
对我来说很清楚
select name from employee
但是,我也获得了所有名称
select name(employee) from employee
我不明白这最后一句话。
我正在使用 PostgreSQL 13 和 pgadmin 4

最佳答案

我想用来自 PostgreSQL docs 的引文来扩展@Abelisto 的回答:

Another special syntactical behavior associated with composite values is that we can use functional notation for extracting a field of a composite value. The simple way to explain this is that the notations field(table) and table.field are interchangeable. For example, these queries are equivalent:

  • SELECT c.name FROM inventory_item c WHERE c.price > 1000;
  • SELECT name(c) FROM inventory_item c WHERE price(c) > 1000;

...

This equivalence between functional notation and field notation makes it possible to use functions on composite types to implement “computed fields”. An application using the last query above wouldn't need to be directly aware that somefunc isn't a real column of the table.

关于postgresql - postgresql中从表名中选择属性名(表名)是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66860047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com