gpt4 book ai didi

PostgreSQL:显示 TYPE 背后的代码

转载 作者:行者123 更新时间:2023-11-29 12:20:49 25 4
gpt4 key购买 nike

假设我创建了一个这样的 TYPE

CREATE TYPE test_type AS ( col1 bigint, col2 varchar(100), col3 integer, col4 numeric )

问题是:我如何查看类型 test_type 的名称背后的内容?

我可以执行 \dT\dT+,但它没有提供我需要的东西(类型的列数据类型及其数量)。

为什么我需要这个?假设有人在过去创建了一个 TYPE,而您需要创建一个返回 SETOF 的函数,但它(您需要返回的类型)可能已经存在实现 - 所以遵循 DRY 原则,你不会真的想做一些已经存在的东西。

最佳答案

要查看复合类型包含哪些属性名称和数据类型,只需使用

\d name_of_a_type

这也意味着 TYPE 的名称必须与同一架构中任何现有类型、域或表的名称不同。

这是因为 CREATE TYPE 语句中使用的一对(属性名称、数据类型)是(根据 manual )

CREATE TYPE

[...] essentially the same as the row type of a table, but using CREATE TYPEavoids the need to create an actual table when all that is wanted isto define a type. A stand-alone composite type is useful as theargument or return type of a function.

关于PostgreSQL:显示 TYPE 背后的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25547601/

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