函数相关操作

最近更新时间: 2024-06-12 15:06:00

  • 建立函数。

     postgres=# CREATE OR REPLACE FUNCTION tbase_f1(a_1 text) returns text as
     postgres-# $$
     postgres$# begin
     postgres$#     return a_1;
     postgres$# end;
     postgres$# $$
     postgres-# language plpgsql; 
     CREATE FUNCTION
     postgres=# CREATE OR REPLACE FUNCTION pgxc.tbase_f2(a_2 text) returns text as
     postgres-# $$
     postgres$# begin
     postgres$#     return a_2;
     postgres$# end;
     postgres$# $$
     postgres-# language plpgsql; 
     CREATE FUNCTION
     postgres=# 
  • \df查看函数列表。

     postgres=# \df
                               List of functions
      Schema |  Name   | Result data type |Argument data types |  Type  
     --------+----------+------------------+---------------------+--------
      pgxc   |tbase_f2 | text             | a_2 text            | normal
      public | tbase_f1 | text             | a_1 text            | normal
     (2 rows)
  • \df+查看函数列表详细信息(包含注释),定义。

     postgres=# \x
     Expanded display is on.
     postgres=# \df+ tbase*
                               List of functions
     -[ RECORD 1 ]-------+--------------------
     Schema              | pgxc
     Name                | tbase_f2
     Result data type    | text
     Argument data types | a_2 text
     Type                | normal
     Volatility          | volatile
     Parallel            | unsafe
     Owner               | tbase
     Security            | invoker
     Access privileges   | 
     Language            | plpgsql
     Source code         |                    +
                         |     begin          +
                        |      return a_2;   +
                         |     end;           +
                        | 
     Description         | 
     -[ RECORD 2 ]-------+--------------------
     Schema              | public
     Name                | tbase_f1
     Result data type    | text
     Argument data types | a_1 text
     Type                | normal
     Volatility          | volatile
     Parallel            | unsafe
     Owner               | tbase
     Security            | invoker
     Access privileges   | 
     Language            | plpgsql
     Source code         |                    +
                         |     begin          +
                         |         return a_1;+
                         |     end;           +
                        | 
     Description         | 
  • \df+函数名显示某个函数的详细信息。

     postgres=# \df+ tbase_f1
                               List of functions
     -[ RECORD 1 ]-------+--------------------
     Schema              | public
     Name                | tbase_f1
     Result data type    | text
     Argument data types | a_1 text
     Type                | normal
     Volatility          | volatile
     Parallel            | unsafe
     Owner               | tbase
     Security            | invoker
     Access privileges   | 
     Language            | plpgsql
     Source code         |                    +
                         |     begin          +
                         |         return a_1;+
                         |     end;           +
                        | 
     Description         | 
  • \df+通配符列出适配的函数。

     postgres=# \df+ tbase*
                               List of functions
     -[ RECORD 1 ]-------+--------------------
     Schema              | pgxc
     Name                | tbase_f2
     Result data type    | text
     Argument data types | a_2 text
     Type                | normal
     Volatility          | volatile
     Parallel            | unsafe
     Owner               | tbase
     Security            | invoker
     Access privileges   | 
     Language            | plpgsql
     Source code         |                    +
                         |     begin          +
                        |      return a_2;   +
                         |     end;           +
                        | 
     Description         | 
     -[ RECORD 2 ]-------+--------------------
     Schema              | public
     Name                | tbase_f1
     Result data type    | text
     Argument data types | a_1 text
     Type                | normal
     Volatility          | volatile
     Parallel            | unsafe
     Owner               | tbase
     Security            | invoker
     Access privileges   | 
     Language            | plpgsql
     Source code         |                    +
                         |     begin          +
                         |         return a_1;+
                         |     end;           +
                        | 
     Description         | 
    
     postgres=# \df+ *f1   
                               List of functions
     -[ RECORD 1 ]-------+--------------------
     Schema              | public
     Name                | tbase_f1
     Result data type    | text
     Argument data types | a_1 text
     Type                | normal
     Volatility          | volatile
     Parallel            | unsafe
     Owner               | tbase
     Security            | invoker
     Access privileges   | 
     Language            | plpgsql
     Source code         |                    +
                         |     begin          +
                         |         return a_1;+
                         |     end;           +
                        | 
     Description