SQL查询之间有什么区别? [英] What are differences between SQL queries?

查看:94
本文介绍了SQL查询之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有以下查询:

SELECT t FROM articles t WHERE t.article_id = 59446

也称为:

SELECT articles FROM articles WHERE articles.article_id = 59446

我听不懂

SELECT articles FROM articles



这是什么意思?为什么起作用?

What does this mean? Why it works?

更新:表 articles没有列 articles

Update: table 'articles' does not have column 'articles'

推荐答案

这是Postgres的对象关系体系结构的结果。对于您创建的每个表,还存在一个具有相同名称的匹配复合类型

This is a result of Postgres' object-relational architecture. For every table you create, there is also a matching composite type with the same name.

运行时

SELECT articles 
FROM articles

您选择的是类型的单列 articles 的表中的strong> articles 。如果您密切注意该查询的输出,您会注意到您的结果仅包含一列,该值用括号括起来,例如(1,Foobar)(如果表文章有两列)。如果运行从文章中选择* ,输出为两列(且没有括号)

you are selecting a single column with the type articles from the table named articles. If you pay close attention to the output of that query you will notice that your result only contains a single column where the value is enclosed in parentheses, e.g. (1,Foobar) (if the table articles has two columns). If you run select * from articles the output is two columns (and no parentheses)

将列的列表放在括号之间会发生同样的事情:

The same thing happens when you put the list of columns between parentheses:

select (article_id, article_name) 
from articles

还会返回列,其中带有包含两个字段的匿名复合类型(这也是列和字段是不一样的)。

also returns a single column with an anonymous composite type containing two fields (this is also a good example that "column" and "field" is not the same thing).

这篇关于SQL查询之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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