Pseudo-Types
GaussDB 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 1 lists all pseudo-types.
Name |
Description |
---|---|
any |
Indicates that a function accepts any input data type. |
anyelement |
Indicates that a function accepts any data type. |
anyarray |
Indicates that a function accepts any array data type. |
anynonarray |
Indicates that a function accepts any non-array data type. |
anyenum |
Indicates that a function accepts any enum data type. |
anyrange |
Indicates that a function accepts any range data type. |
cstring |
Indicates that a function accepts or returns a null-terminated C string. |
internal |
Indicates that a function accepts or returns a server-internal data type. |
language_handler |
Indicates that a procedural language call handler is declared to return language_handler. |
fdw_handler |
Indicates that a foreign-data wrapper handler is declared to return fdw_handler. |
record |
Identifies a function returning an unspecified row type. |
trigger |
Indicates that a trigger function is declared to return trigger. |
void |
Indicates that a function returns no value. |
opaque |
Indicates an obsolete type name that formerly served all the above purposes. |
Functions coded in C language (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.
Functions coded in procedural languages can use pseudo-types only as allowed by their implementation languages. At present the procedural languages all forbid use of a pseudo-type as argument type, and allow only void and record as a result type. Some also support polymorphic functions using the anyelement, anyarray, anynonarray, anyenum, and anyrange types.
Each location (parameter or return value) declared as the anyelement type is allowed to have any specific actual data type, but they must all be of the same actual type in any given query.
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 calling in an SQL query. If a function has at least one internal-type argument then it cannot be called from SQL. You are advised not to create any function that is declared to return internal unless it has at least one internal argument.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
-- Create a table. gaussdb=# CREATE TABLE t1 (a int); -- Insert two data records. gaussdb=# INSERT INTO t1 values(1),(2); -- Create the showall() function. gaussdb=# CREATE OR REPLACE FUNCTION showall() RETURNS SETOF record AS $$ SELECT count(*) from t1; $$ LANGUAGE SQL; -- Call the showall() function. gaussdb=# SELECT showall(); showall --------- (2) (1 row) -- Delete the function. gaussdb=# DROP FUNCTION showall(); -- Delete the table. gaussdb=# DROP TABLE t1; |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot