8.21. Pseudo-Types

8.21. Pseudo-Types

8.21.僞類型

The PostgreSQL type system contains a number of special-purpose entries that are collectively called pseudo-types. A pseudo-type cannot be used as a column data type, but it can be used to declare a function's argument or result type. Each of the available pseudo-types is useful in situations where a function's behavior does not correspond to simply taking or returning a value of a specific SQL data type. Table 8.25 lists the existing pseudo-types.

PostgreSQL類型系統包含許多特殊用途的條目,這些條目統稱爲僞類型。 僞類型不能用作列數據類型,但可以用來聲明函數的參數或結果類型。每個可用的僞類型在函數的行爲不僅僅對應於獲取或返回特定SQL數據類型的值的情況下很有用。 表8.25列出了現有的僞類型。

 

uploading.4e448015.gif轉存失敗重新上傳取消

uploading.4e448015.gif轉存失敗重新上傳取消

Functions coded in C (whether built-in or dynamically loaded) can be declared to accept or return any of these pseudo data types. It is up to the function author to ensure that the function will behave safely when a pseudo-type is used as an argument type.

用C編碼的函數(無論是內置的還是動態加載的)可以接受或返回任何這些僞數據類型。函數編寫者有責任確保在將僞類型用作參數類型時該函數將安全地運行。

 

Functions coded in procedural languages can use pseudo-types only as allowed by their implementation languages. At present most procedural languages forbid use of a pseudo-type as an argument type, and allow only void and record as a result type (plus trigger or event_trigger when the function is used as a trigger or event trigger). Some also support polymorphic functions using the types anyelement, anyarray, anynonarray, anyenum, and anyrange.

用過程語言編碼的函數只能在其實現語言允許的情況下使用僞類型。 目前,大多數程序語言都禁止將僞類型用作參數類型,並且僅允許將void和record作爲結果類型(當將函數用作觸發器或事件觸發器時,則添加trigger或event_trigger)。 一些還使用類型anyelement,anyarray,anynonarray,anyenum和anyrange支持多態函數。

 

The internal pseudo-type is used to declare functions that are meant only to be called internally by the database system, and not by direct invocation in an SQL query. If a function has at least one internal-type argument then it cannot be called from SQL. To preserve the type safety of this restriction it is important to follow this coding rule: do not create any function that is declared to return internal unless it has at least one internal argument.

內部僞類型用於聲明僅在數據庫系統內部進行調用的函數,而不是在SQL查詢中直接調用的函數。 如果一個函數至少有一個內部類型參數,則不能從SQL調用它。 爲了保持此限制的類型安全性,請務必遵循此編碼規則:請勿創建任何聲明爲返回內部函數的函數,除非該函數至少具有一個內部參數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章