PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, June 29, 2022

[FIXED] How do I select the comment on a Postgres stored procedure

 June 29, 2022     comments, function, postgresql, sql, stored-procedures     No comments   

Issue

Suppose I have a procedure, call it my_procedure:

CREATE OR REPLACE my_procedure(X INT);

Then I write:

COMMENT ON my_procedure IS 'My comment'

How do I then use a SELECT statement to retrieve that comment?

This looks promising:

SELECT *
FROM pg_description
WHERE objoid = WHAT_SHOULD_THIS_BE?;

but I have no idea how to find the objoid of my_procedure.

Any help is appreciated, thanks!


Solution

  SELECT pg_catalog.obj_description(p.oid, 'pg_proc') as "comment"
  FROM pg_catalog.pg_proc AS p
  WHERE p.proname = 'my_procedure';

You may want to also check the values in the pronamespace and proargtypes and prokind columns if there's a chance of multiple procedures or functions having the same name

I got this information by using psql -E and looking at the queries it made.



Answered By - Jasen
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing