dbTalk Databases Forums  

Function to retrieve object definition

comp.databases.postgresql comp.databases.postgresql


Discuss Function to retrieve object definition in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mladen Gogala
 
Posts: n/a

Default Function to retrieve object definition - 06-13-2010 , 04:48 AM






I know that I can write one, using the information_schema or pg_catalog
information, preferably the latter, and get DDL for tables, indexes and
routines as a result. Another popular database variety has a package
DBMS_METADATA which contains the function named "GET_DDL", which does
precisely what I want.
Unfortunately, I got lazy and spoiled by using the other RDBMS systems
and would like to know 2 things:

1) Is there a function that will take schema,name and object type as
arguments and return the create statement for that object? For
indexes, it's trivial, because pg_indexes table contains the
create statement for all indexes. Routines can also be easily
obtained from the pg_proc which contains arguments, defaults and
source. Same goes for the views.
All elements are easy to find but creating the function itself
would be a bit of work and I don't feel like doing it, if I can
use somebody else's work.
2) Is there a ready-made query that will join pg_class, pg_attribute and
pg_type to produce effect similar to \d? Anything of that nature that
emulates DBA_IND_COLUMNS and DBA_CONS_COLUMNS? I find those two tables
very useful and would like having them in my Postgres databases very
much. If there is a noble soul who feels like sharing....



--
http://mgogala.byethost5.com

Reply With Quote
  #2  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Function to retrieve object definition - 06-13-2010 , 05:00 AM






Mladen Gogala wrote on 13.06.2010 11:48:
Quote:
I know that I can write one, using the information_schema or pg_catalog
information, preferably the latter, and get DDL for tables, indexes and
routines as a result. Another popular database variety has a package
DBMS_METADATA which contains the function named "GET_DDL", which does
precisely what I want.
Unfortunately, I got lazy and spoiled by using the other RDBMS systems
and would like to know 2 things:

1) Is there a function that will take schema,name and object type as
arguments and return the create statement for that object? For
indexes, it's trivial, because pg_indexes table contains the
create statement for all indexes. Routines can also be easily
obtained from the pg_proc which contains arguments, defaults and
source. Same goes for the views.
All elements are easy to find but creating the function itself
would be a bit of work and I don't feel like doing it, if I can
use somebody else's work.
2) Is there a ready-made query that will join pg_class, pg_attribute and
pg_type to produce effect similar to \d? Anything of that nature that
emulates DBA_IND_COLUMNS and DBA_CONS_COLUMNS? I find those two tables
very useful and would like having them in my Postgres databases very
much. If there is a noble soul who feels like sharing....

I guess the closes thing are the pg_get_XXXdef functions()

http://www.postgresql.org/docs/curre...ions-info.html

Reply With Quote
  #3  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Function to retrieve object definition - 06-13-2010 , 12:45 PM



On Sun, 13 Jun 2010 12:00:31 +0200, Thomas Kellerer wrote:


Quote:
I guess the closes thing are the pg_get_XXXdef functions()
Unfortunately, there exist no function such that XXX = 'table'. Well,
I'll make one myself and post the code, that is if anyone is interested.
It should be a relatively simple join between pg_class and pg_attribute,
if the column type is simple, built-in type. I am not sure how well will
it work with the domains.



--
http://mgogala.byethost5.com

Reply With Quote
  #4  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Function to retrieve object definition - 06-14-2010 , 01:10 AM



Mladen Gogala, 13.06.2010 19:45:
Quote:
On Sun, 13 Jun 2010 12:00:31 +0200, Thomas Kellerer wrote:


I guess the closes thing are the pg_get_XXXdef functions()

Unfortunately, there exist no function such that XXX = 'table'. Well,
I'll make one myself and post the code, that is if anyone is interested.
It should be a relatively simple join between pg_class and pg_attribute,
if the column type is simple, built-in type. I am not sure how well will
it work with the domains.
A "non-SQL" solution would be to use "pg_dump -s -t mytable"

Regards
Thomas

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.