兩種方法:
創新互聯公司專業為企業提供瀘縣網站建設、瀘縣做網站、瀘縣網站設計、瀘縣網站制作等企業網站建設、網頁設計與制作、瀘縣企業網站模板建站服務,10年瀘縣做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
方法一:查詢pg_proc:
osdba=# select prosrc from pg_proc where proname='get_username';
prosrc
--------------------------------------------------------
declare
ret text;
begin
SELECT name into ret from tang01 where id=userid;
return ret;
end;
(1 row)
方法二:調用pg_catalog.pg_get_functiondef函數:
osdba=# select pg_get_functiondef('get_username'::regproc);
pg_get_functiondef
----------------------------------------------------------------
CREATE OR REPLACE FUNCTION public.get_username(userid integer)
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
ret text;
begin
SELECT name into ret from tang01 where id=userid;
return ret;
end;
$function$
最近在寫postgres的函數,整理下常用語法備忘
regexp_split_to_table 字符串分割為表格
regexp_split_to_array 字符串分割為數組
定義內部變量
執行動態sql,并傳入參數
執行動態sql,取出結果
打印變量
字符串拼接
在postgreSQL中用select語句就可以調用函數了,包括自定義函數:
select * from your_function(param1, param2, ) s;
如果你不需要函數的返回值,也可以用perform語句來調用:
perform your_function(param1, param2, ..);
以下答案來源于Navicat中文網站,如果需要Navicat軟件的話,可以到海淘正版專業軟件網站麥軟下載
點擊 Navicat 主界面上的其他-語言,打開語言對象列表。注意:PostgreSQL 8.0 或以上版本支持“注釋”選項卡。
Navicat for PostgreSQL
Navicat for PostgreSQL 語言常規屬性:
擁有者:語言的擁有者,支持 PostgreSQL 8.3 或以上版本。
操作符的模式和操作符:以前注冊的函數名被調用來運行過程語言函數。過程語言的調用操作符用已編譯的語言寫,例如 C與版本 1 調用轉換。在 PostgreSQL 注冊為一個沒有引數的函數,返回 language_handler 類型,占位符類型只是用來定義函數為調用操作符。
驗證符的模式和驗證符:當在語言中新建函數時以前注冊的函數名被調用來驗證新函數。如果沒有指定驗證符函數,新函數創建時將不會檢查。驗證符函數必須有類型 oid 的引數,這是要創建的函數 OID,通常返回void。
驗證符函數通常會檢查函數主體的語法正確性,但它也可以看函數的其他屬性。例如,如果語言不可以處理某些引數類型。要發出錯誤信號,驗證符函數應使用 ereport() 函數,函數的返回值將被忽略。
信任:指定語言的調用操作符是安全的,也就是說,它不提供未經授權的用戶任何功能來繞過訪問限制。當注冊語言時,如果忽略該關鍵字,只有 PostgreSQL 超級用戶權限的用戶可以使用該語言創建新函數。
有的。PostgreSQL內建有分析函數,PostgreSQL稱之為Window Function,有如下這些:
row_number()
rank()
dense_rank()
percent_rank()
cume_dist()
ntile(num_buckets integer)
lag(value any [, offset integer [, default any ]])
lead(value any [, offset integer [, default any ]])
first_value(value any)
last_value(value any)
nth_value(value any, nth integer)
具體說明參看PostgreSQL說明文件中Funcstions Operates下的Winow Functions。
ABORT -- abort the current transaction
ALTER DATABASE -- change a database
ALTER GROUP -- add users to a group or remove users from a group
ALTER TABLE -- change the definition of a table
ALTER TRIGGER -- change the definition of a trigger
ALTER USER -- change a database user account
ANALYZE -- collect statistics about a database
BEGIN -- start a transaction block
CHECKPOINT -- force a transaction log checkpoint
CLOSE -- close a cursor
CLUSTER -- cluster a table according to an index
COMMENT -- define or change the comment of an object
COMMIT -- commit the current transaction
COPY -- copy data between files and tables
CREATE AGGREGATE -- define a new aggregate function
CREATE CAST -- define a user-defined cast
CREATE CONSTRAINT TRIGGER -- define a new constraint trigger
CREATE CONVERSION -- define a user-defined encoding conversion
CREATE DATABASE -- create a new database
CREATE DOMAIN -- define a new domain
CREATE FUNCTION -- define a new function
CREATE GROUP -- define a new user group
CREATE INDEX -- define a new index
CREATE LANGUAGE -- define a new procedural language
CREATE OPERATOR -- define a new operator
CREATE OPERATOR CLASS -- define a new operator class for indexes
CREATE RULE -- define a new rewrite rule
CREATE SCHEMA -- define a new schema
CREATE SEQUENCE -- define a new sequence generator
CREATE TABLE -- define a new table
CREATE TABLE AS -- create a new table from the results of a query
CREATE TRIGGER -- define a new trigger
CREATE TYPE -- define a new data type
CREATE USER -- define a new database user account
CREATE VIEW -- define a new view
DEALLOCATE -- remove a prepared query
DECLARE -- define a cursor
DELETE -- delete rows of a table
DROP AGGREGATE -- remove a user-defined aggregate function
DROP CAST -- remove a user-defined cast
DROP CONVERSION -- remove a user-defined conversion
DROP DATABASE -- remove a database
DROP DOMAIN -- remove a user-defined domain
DROP FUNCTION -- remove a user-defined function
DROP GROUP -- remove a user group
DROP INDEX -- remove an index
DROP LANGUAGE -- remove a user-defined procedural language
DROP OPERATOR -- remove a user-defined operator
DROP OPERATOR CLASS -- remove a user-defined operator class
DROP RULE -- remove a rewrite rule
DROP SCHEMA -- remove a schema
DROP SEQUENCE -- remove a sequence
DROP TABLE -- remove a table
DROP TRIGGER -- remove a trigger
DROP TYPE -- remove a user-defined data type
DROP USER -- remove a database user account
DROP VIEW -- remove a view
END -- commit the current transaction
EXECUTE -- execute a prepared query
EXPLAIN -- show the execution plan of a statement
FETCH -- retrieve rows from a table using a cursor
GRANT -- define access privileges
INSERT -- create new rows in a table
LISTEN -- listen for a notification
LOAD -- load or reload a shared library file
LOCK -- explicitly lock a table
MOVE -- position a cursor on a specified row of a table
NOTIFY -- generate a notification
PREPARE -- create a prepared query
REINDEX -- rebuild corrupted indexes
RESET -- restore the value of a run-time parameter to a default value
REVOKE -- remove access privileges
ROLLBACK -- abort the current transaction
SELECT -- retrieve rows from a table or view
SELECT INTO -- create a new table from the results of a query
SET -- change a run-time parameter
SET CONSTRAINTS -- set the constraint mode of the current transaction
SET SESSION AUTHORIZATION -- set the session user identifier and the current user identifier of the current session
SET TRANSACTION -- set the characteristics of the current transaction
SHOW -- show the value of a run-time parameter
START TRANSACTION -- start a transaction block
TRUNCATE -- empty a table
UNLISTEN -- stop listening for a notification
UPDATE -- update rows of a table
VACUUM -- garbage-collect and optionally analyze a database
--是指這個命令列表嗎?
網頁標題:postgresql函數的簡單介紹
鏈接地址:http://www.yijiale78.com/article38/dsccgpp.html
成都網站建設公司_創新互聯,為您提供商城網站、域名注冊、全網營銷推廣、App設計、動態網站、搜索引擎優化
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯