这个 PostgreSQL 查询完成了什么?
我最近从 MySQL 切换到 PostgreSQL,在遵循许多“常规”查询后,我注意到一个额外的查询。
紧接着...
SELECT "documents".* FROM "documents" WHERE ("documents"."id" = 1) LIMIT 1
执行:
SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"documents"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
最后一个查询完成了什么?这里返回哪些信息?
I recently switched from MySQL to PostgreSQL and I noticed one additional query after following many "regular" queries.
Immediately after this...
SELECT "documents".* FROM "documents" WHERE ("documents"."id" = 1) LIMIT 1
this is executed:
SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"documents"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
What does this last query accomplish? Which information is returned here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该查询正在获取有关表
documents
的信息。目录 pg_attribute 存储有关表列的信息。
目录 pg_attrdef 存储列默认值。
a.attrelid
:该列所属的表。a.attname
:列名称。a.atttypid
:该列的数据类型。a.atttypmod
:记录在表创建时提供的特定于类型的数据(例如,varchar 列的最大长度)。它被传递给特定于类型的输入函数和长度强制函数。对于不需要 atttypmod 的类型,该值通常为 -1。d.adsrc
:默认值的人类可读表示。a.attnotnull
:这表示非空约束。例如,ORM 可以使用此信息来构建类和对象之间的映射。数据库中的表。
The query is fetching information about the table
documents
.The catalog pg_attribute stores information about table columns.
The catalog pg_attrdef stores column default values.
a.attrelid
: The table this column belongs to.a.attname
: The column name.a.atttypid
: The data type of this column.a.atttypmod
: Records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). It is passed to type-specific input functions and length coercion functions. The value will generally be -1 for types that do not need atttypmod.d.adsrc
: A human-readable representation of the default value.a.attnotnull
: This represents a not-null constraint.This information could for example be used by an ORM to construct a mapping between a class and a table in the database.