30

Using PostgreSQL with pgAdmin, and was wondering if there is a way to search ALL of the functions of a database for a particular text.

Is this possible?

jlars62
  • 7,183
  • 7
  • 39
  • 60
  • In my case, I was specifically looking to see which functions used the `security definer` parameter, but couldn't find anything when I searched (with @Andreas's code) because those parameters aren't stored in prosrc. So, I ran `psql -E` argument to see what query it used under the hood for `\df+` and modified that query for the security column. A similar strategy could be used for other procedure attributes. – combinatorist Jul 18 '22 at 22:03

3 Answers3

57

Something like this should work:

select proname, prosrc from pg_proc where prosrc like '%search text%';

see How to display the function, procedure, triggers source code in postgresql?

Andreas
  • 4,937
  • 2
  • 25
  • 35
5

If schema info is required too (we work with many):

select
    nspname,
    proname,
    prosrc 
from pg_catalog.pg_proc pr
join pg_catalog.pg_namespace ns on ns.oid = pr.pronamespace
where prosrc ilike '%search text%'
steevee
  • 2,238
  • 1
  • 21
  • 16
1

Answers posted by @Andreas and @steevee didn't work out for me, so I had to do the following way:

  1. First enabled extended display by running \x
  2. Then \df+ to list down all stored procedures (in less mode by enabling extended display above) then press / key to search for a keyword.
Ahsaan Yousuf
  • 685
  • 7
  • 16