在PostgreSQL中,什么时候可以使用标识符号代替其名称? [英] When can we use an identifier number instead of its name in PostgreSQL?

查看:168
本文介绍了在PostgreSQL中,什么时候可以使用标识符号代替其名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个软件,需要删除用户提供的数字,但是不幸的是,某些元素(例如列名(与用户输入无关))也可以用数字表示。因此,我正在寻找完整的参考资料,以了解何时在查询中可以用id表示列名或(也许是表名)。

I am developing a software need to remove user provided numbers but unfortunately some elements like column names (unrelated to user input) also can be represent by numbers. So I am looking for a complete reference to know when a column name or (maybe table name) can represented in a query by an id.

例如在下面的查询中这种情况已经确立:

For example in the query below this situation is established:

 select * from first group by 1,2,3;


推荐答案

输出的位置引用列在 GROUP BY中有效 ORDER BY 子句的 SELECT 语句。

Positional references to output columns are valid in the GROUP BY and ORDER BY clauses of a SELECT statement.


GROUP BY 条款

表达式可以是输入列名称,也可以是输出列(选择列表项)的名称或序数

GROUP BY Clause
expression can be an input column name, or the name or ordinal number of an output column (SELECT list item)

ORDER BY 条款

每个表达式可以是输出列
(选择列表项)的名称或序号

还有 直接打开


DISTINCT ON 表达式使用相同的规则进行解释例如 ORDER BY

The DISTINCT ON expressions are interpreted using the same rules as for ORDER BY.

示例:

  • Select first row in each GROUP BY group?

这篇关于在PostgreSQL中,什么时候可以使用标识符号代替其名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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