List of Stored Procs on a Redshift database

0

Hello,

Where can I see the list of Stored Procs that were created on a database in Redshift?
I can only see the list of tables in the Public schema of the database.

Thanks
RP

已提问 5 年前3310 查看次数
3 回答
1

CREATE OR REPLACE VIEW public.v_get_stored_proc_params AS WITH arguments AS (SELECT oid, arg_num , arg_names[arg_num] AS arg_name , arg_types[arg_num - 1] AS arg_type FROM (SELECT GENERATE_SERIES(1, arg_count) AS arg_num , arg_names, arg_types, oid FROM (SELECT oid , proargnames AS arg_names , proargtypes AS arg_types , pronargs AS arg_count FROM pg_proc WHERE proowner != 1 AND prolang = 100356 ) t) t) SELECT n.nspname AS schema_name , p.proname AS proc_name , p.oid::INT AS proc_id , a.arg_num AS order , NVL(a.arg_name, '') AS parameter , FORMAT_TYPE(a.arg_type, NULL) AS data_type FROM pg_proc p LEFT JOIN pg_namespace n ON n.oid = p.pronamespace LEFT JOIN arguments a ON a.oid = p.oid WHERE p.proowner != 1 AND p.prolang = 100356 ORDER BY 1,2,3,4;

AWS
已回答 2 年前
  • the answer looks correct but may do with some formatting

0

https://docs.aws.amazon.com/redshift/latest/dg/r_PG_PROC_INFO.html

PG_PROC_INFO
PG_PROC_INFO is an Amazon Redshift system view built on the PostgreSQL catalog table PG_PROC and the internal catalog table PG_PROC_EXTENDED. PG_PROC_INFO includes details about stored procedures and functions, including information related to output arguments, if any.

Here is a sample query over this view:

SELECT p.proname sp_name , n.nspname sp_schema , p.proargnames sp_args 
FROM pg_catalog.pg_namespace n 
JOIN pg_catalog.pg_proc p ON p.pronamespace = n.oid 
WHERE p.proowner > 1 AND p.prolang = 100125 ;

Once you know the name of the stored procedure you can retrieve the DDL to create it using SHOW PROCEDURE my_proc;

已回答 5 年前
AWS
专家
已审核 2 年前
0

Create a view so you can keep using it:

CREATE OR REPLACE VIEW
public.v_get_stored_proc_params AS
SELECT
    n.nspname,
    b.usename,
    p.proname,
    p.prosrc
FROM
    pg_catalog.pg_namespace n
JOIN pg_catalog.pg_proc p ON
    pronamespace = n.oid
JOIN pg_catalog.pg_user b on
    b.usesysid = p.proowner
WHERE
    nspname not in ('information_schema',
    'pg_catalog')

AWS
已回答 2 年前
AWS
专家
已审核 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则