Thread: Oracle Equivalent queries in Postgres

Oracle Equivalent queries in Postgres

From
Sivannarayanreddy
Date:
Hello,<br /> I am checking the compatibility of my product with Postgres database and i stucked in forming the below
oracleequivalent queries in Postgres database, Could some one help me pleaseee<br /><br /> 1) Trying to get index and
correspondingcolumns  information of all the tables in mentioned schema<br /><br /> select  inx.table_name as
table_name,inx.index_name as index_name,column_name, case  ( when inx.index_type = 'IOT - TOP' then 'Y' else 'N' 
end,                                              <br />     case    <br />      when inx.uniqueness = 'UNIQUE' then
'Y'      <br />      when inx.uniqueness = 'NONUNIQUE' then 'N'     <br />     
end,                                               <br />      'N' as ignore_dup_key,                             <br
/>     cast(inc.column_position as NUMBER(10))            <br />      from    all_indexes        
inx,                          <br />      all_ind_columns     inc                            <br />       where  
inx.owner          = '" + database.toUpperCase() + "'        <br />       and     inx.table_name      =
inc.table_name              <br />       and     inx.index_name      = inc.index_name                <br />      
and    inx.owner           = inc.index_owner              <br />      and     inx.owner           =
inc.table_owner             <br />      and     inx.dropped         = 'NO' <br />      and     inx.table_name       =
'"+ tableName.toUpperCase() + "'<br />      order by inx.table_name, inx.index_name, cast(inc.column_position as
NUMBER(10))<br/><br /><br /> 2) Trying to get the columns information of all the tables in mentioned schema<br /><br />
 select  tab.TABLE_NAME, <br />                   col.COLUMN_NAME, <br />                   col.DATA_TYPE, <br />
                 cast(case  when col.CHAR_COL_DECL_LENGTH is NULL then col.DATA_PRECISION else col.CHAR_LENGTH end  as
NUMBER(10)),<br />                   cast(col.NULLABLE as CHAR(1)), <br />                   cast(col.COLUMN_ID as
NUMBER(10))<br />                   <br />          from    all_tab_columns    col, <br />                 
all_tables        tab <br />          where   tab.TABLE_NAME        = col.TABLE_NAME <br />          and    
tab.OWNER            = col.OWNER <br />          and     tab.OWNER             = '" + database.toUpperCase() + "' <br
/>         and     tab.DROPPED           = 'NO' <br />         and     tab.TABLE_NAME       = '" +
tableName.toUpperCase()+ "' <br />         order by tab.TABLE_NAME, cast(col.COLUMN_ID as NUMBER(10))<br />         <br
/><br/><br /><div class="moz-signature"></div><p style="margin-bottom: 0in;"><strong><font color="#939598"><font
face="Arial"><fontsize="2">Sivannarayanareddy Nusum</font></font></font></strong><strong><font color="#000080">
</font></strong><strong><fontcolor="#000080"><font face="Arial"><font size="2">|
</font></font></font></strong><strong><fontcolor="#0000ff"><font face="Arial"><font size="2">System Analyst(Moneta
GDO)</font></font></font></strong><fontcolor="#000080"> </font><p style="margin-bottom: 0in;"><font face="Arial"><font
size="1"style="font-size: 8pt;"><img align="BOTTOM" border="0" height="71" name="graphics1"
src="cid:part1.01010006.07070008@subexworld.com"width="190" /></font></font><p style="margin-bottom: 0in;"><font
color="#808080"><fontface="Arial"><font size="1" style="font-size: 8pt;">Subex Limited, Adarsh Tech Park, Outer Ring
Road,Devarabisannalli, Bangalore – 560037, India.<br /></font></font></font><font color="#a01e55"><font
face="Arial"><fontsize="1" style="font-size: 8pt;"><b>Phone:</b></font></font></font><font color="#000000">
</font><fontcolor="#000000"><font face="Arial"><font size="1" style="font-size: 8pt;">+91 80 6696 3371;
</font></font></font><fontcolor="#a01e55"><font face="Arial"><font size="1" style="font-size:
8pt;"><b>Mobile:</b></font></font></font><fontcolor="#000000"> </font><font color="#000000"><font face="Arial"><font
size="1"style="font-size: 8pt;">+91 9902065831</font></font></font><font color="#c1272d">  </font><font
color="#a01e55"><fontface="Arial"><font size="1" style="font-size:
8pt;"><b>Fax:</b></font></font></font><fontcolor="#000000"> </font><font color="#000000"><font face="Arial"><font
size="1"style="font-size: 8pt;">+91 80 6696 3333; </font></font></font><p style="margin-bottom: 0in;"><font
color="#a01e55"><fontface="Arial"><font size="1" style="font-size: 8pt;"><b>Email:</b></font></font></font><font
color="#c1272d"> </font><font color="#c1272d"><font face="Arial"><font size="1" style="font-size: 8pt;"><a
href="mailto:email.id@subexworld.com">sivannarayanreddy@subexworld.com</a>;</font></font></font><font
color="#a01e55"><fontface="Arial"><font size="1" style="font-size: 8pt;"><b>URL:</b></font></font></font><font
color="#c1272d"> </font><a href="http://www.subexworld.com/"><font color="#c1272d"><font face="Arial"><font size="1"
style="font-size:              8pt;">www.subexworld.com</font></font></font></a><font color="#c1272d"> </font><p
style="margin-bottom:0in;"><font color="#c1272d"> </font><p class="msonormal"><font color="#808080"><font
face="Arial"><fontsize="1" style="font-size: 8pt;"><i>Disclaimer: This e-mail is bound by the terms and conditions
describedat </i></font></font></font><a href="http://www.subexworld.com/mail-disclaimer.html"><font face="Arial"><font
size="1"style="font-size: 8pt;"><i>http://www.subexworld.com/mail-disclaimer.html</i></font></font></a><font
color="#808080"><br/></font> 

Re: Oracle Equivalent queries in Postgres

From
Pavel Stehule
Date:
Hello

PostgreSQL uses a different system tables than Oracle. Try to use a standardized information_schema instead - these views are same on PostgreSQL and Oracle.

http://www.postgresql.org/docs/current/static/information-schema.html

Regards

Pavel Stehule




2011/2/16 Sivannarayanreddy <sivannarayanreddy@subexworld.com>
Hello,
I am checking the compatibility of my product with Postgres database and i stucked in forming the below oracle equivalent queries in Postgres database, Could some one help me pleaseee

1) Trying to get index and corresponding columns  information of all the tables in mentioned schema

select  inx.table_name as table_name, inx.index_name as index_name,column_name, case  ( when inx.index_type = 'IOT - TOP' then 'Y' else 'N'  end,                                              
    case   
     when inx.uniqueness = 'UNIQUE' then 'Y'      
     when inx.uniqueness = 'NONUNIQUE' then 'N'    
     end,                                               
     'N' as ignore_dup_key,                            
     cast(inc.column_position as NUMBER(10))           
     from    all_indexes         inx,                          
     all_ind_columns     inc                           
      where   inx.owner           = '" + database.toUpperCase() + "'       
      and     inx.table_name      = inc.table_name              
      and     inx.index_name      = inc.index_name               
      and     inx.owner           = inc.index_owner             
     and     inx.owner           = inc.table_owner             
     and     inx.dropped         = 'NO'
     and     inx.table_name       = '" + tableName.toUpperCase() + "'
     order by inx.table_name, inx.index_name, cast(inc.column_position as NUMBER(10))


2) Trying to get the columns information of all the tables in mentioned schema

 select   tab.TABLE_NAME,
                  col.COLUMN_NAME,
                  col.DATA_TYPE,
                  cast(case  when col.CHAR_COL_DECL_LENGTH is NULL then col.DATA_PRECISION else col.CHAR_LENGTH end  as NUMBER(10)),
                  cast(col.NULLABLE as CHAR(1)),
                  cast(col.COLUMN_ID as NUMBER(10))
                 
         from    all_tab_columns    col,
                 all_tables         tab
         where   tab.TABLE_NAME        = col.TABLE_NAME
         and     tab.OWNER             = col.OWNER
         and     tab.OWNER             = '" + database.toUpperCase() + "'
         and     tab.DROPPED           = 'NO'
        and     tab.TABLE_NAME       = '" + tableName.toUpperCase() + "'
        order by tab.TABLE_NAME, cast(col.COLUMN_ID as NUMBER(10))
       


Sivannarayanareddy Nusum | System Analyst(Moneta GDO)

Subex Limited, Adarsh Tech Park, Outer Ring Road, Devarabisannalli, Bangalore – 560037, India.
Phone: +91 80 6696 3371; Mobile: +91 9902065831  Fax: +91 80 6696 3333;

Email:  sivannarayanreddy@subexworld.com; URL:  www.subexworld.com

 

Disclaimer: This e-mail is bound by the terms and conditions described at http://www.subexworld.com/mail-disclaimer.html


Attachment

Re: Oracle Equivalent queries in Postgres

From
Thomas Kellerer
Date:
Pavel Stehule, 16.02.2011 11:50:
> Try to use a standardized information_schema instead - these views are same on PostgreSQL and Oracle.

Unfortunately they are not the same: Oracle does not support INFORMATION_SCHEMA

Regards
Thomas



Re: Oracle Equivalent queries in Postgres

From
Pavel Stehule
Date:
hello

list of tables http://www.postgresql.org/docs/current/static/infoschema-tables.html
information about column http://www.postgresql.org/docs/current/static/infoschema-columns.html

information about indexes - it's not part of ANSI/SQL so you have to look to pg_index or pg_indexes.

Regards

Pavel Stehule


2011/2/16 Sivannarayanreddy <sivannarayanreddy@subexworld.com>
Hi Pavel,
In the given link, there are no views which can give information about indexes.

Is it possible for you to give me the equivalent queries in postgres?

Sivannarayanareddy Nusum | System Analyst(Moneta GDO)

Subex Limited, Adarsh Tech Park, Outer Ring Road, Devarabisannalli, Bangalore – 560037, India.
Phone: +91 80 6696 3371; Mobile: +91 9902065831  Fax: +91 80 6696 3333;

Email:  sivannarayanreddy@subexworld.com; URL:  www.subexworld.com

 

Disclaimer: This e-mail is bound by the terms and conditions described at http://www.subexworld.com/mail-disclaimer.html


On 2/16/2011 4:20 PM, Pavel Stehule wrote:
Hello

PostgreSQL uses a different system tables than Oracle. Try to use a standardized information_schema instead - these views are same on PostgreSQL and Oracle.

http://www.postgresql.org/docs/current/static/information-schema.html

Regards

Pavel Stehule




2011/2/16 Sivannarayanreddy <sivannarayanreddy@subexworld.com>
Hello,
I am checking the compatibility of my product with Postgres database and i stucked in forming the below oracle equivalent queries in Postgres database, Could some one help me pleaseee

1) Trying to get index and corresponding columns  information of all the tables in mentioned schema

select  inx.table_name as table_name, inx.index_name as index_name,column_name, case  ( when inx.index_type = 'IOT - TOP' then 'Y' else 'N'  end,                                              
    case   
     when inx.uniqueness = 'UNIQUE' then 'Y'      
     when inx.uniqueness = 'NONUNIQUE' then 'N'    
     end,                                               
     'N' as ignore_dup_key,                            
     cast(inc.column_position as NUMBER(10))           
     from    all_indexes         inx,                          
     all_ind_columns     inc                           
      where   inx.owner           = '" + database.toUpperCase() + "'       
      and     inx.table_name      = inc.table_name              
      and     inx.index_name      = inc.index_name               
      and     inx.owner           = inc.index_owner             
     and     inx.owner           = inc.table_owner             
     and     inx.dropped         = 'NO'
     and     inx.table_name       = '" + tableName.toUpperCase() + "'
     order by inx.table_name, inx.index_name, cast(inc.column_position as NUMBER(10))


2) Trying to get the columns information of all the tables in mentioned schema

 select   tab.TABLE_NAME,
                  col.COLUMN_NAME,
                  col.DATA_TYPE,
                  cast(case  when col.CHAR_COL_DECL_LENGTH is NULL then col.DATA_PRECISION else col.CHAR_LENGTH end  as NUMBER(10)),
                  cast(col.NULLABLE as CHAR(1)),
                  cast(col.COLUMN_ID as NUMBER(10))
                 
         from    all_tab_columns    col,
                 all_tables         tab
         where   tab.TABLE_NAME        = col.TABLE_NAME
         and     tab.OWNER             = col.OWNER
         and     tab.OWNER             = '" + database.toUpperCase() + "'
         and     tab.DROPPED           = 'NO'
        and     tab.TABLE_NAME       = '" + tableName.toUpperCase() + "'
        order by tab.TABLE_NAME, cast(col.COLUMN_ID as NUMBER(10))
       


Sivannarayanareddy Nusum | System Analyst(Moneta GDO)

Subex Limited, Adarsh Tech Park, Outer Ring Road, Devarabisannalli, Bangalore – 560037, India.
Phone: +91 80 6696 3371; Mobile: +91 9902065831  Fax: +91 80 6696 3333;

Email:  sivannarayanreddy@subexworld.com; URL:  www.subexworld.com

 

Disclaimer: This e-mail is bound by the terms and conditions described at http://www.subexworld.com/mail-disclaimer.html



Attachment

Re: Oracle Equivalent queries in Postgres

From
Pavel Stehule
Date:
2011/2/16 Thomas Kellerer <spam_eater@gmx.net>:
> Pavel Stehule, 16.02.2011 11:50:
>>
>> Try to use a standardized information_schema instead - these views are
>> same on PostgreSQL and Oracle.
>
> Unfortunately they are not the same: Oracle does not support
> INFORMATION_SCHEMA
>

sorry, I expected so all mature databases support it.

Regards
Pavel

> Regards
> Thomas
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


Re: Oracle Equivalent queries in Postgres

From
Thomas Kellerer
Date:
Pavel Stehule, 16.02.2011 12:20:
>> Unfortunately they are not the same: Oracle does not support
>> INFORMATION_SCHEMA
>>
>
> sorry, I expected so all mature databases support it.

Yes, this is really hard to understand.

I would assume creating the INFORMATION_SCHEMA views based on the existing Oracle views is just a matter of maybe 3-4
daysof days work. So it is really not understandable that Oracle does not support this.
 

But then they probably don't care - after all it's Oracle.

Regards
Thomas



Re: Oracle Equivalent queries in Postgres

From
Tom Lane
Date:
Thomas Kellerer <spam_eater@gmx.net> writes:
> Pavel Stehule, 16.02.2011 12:20:
>>> Unfortunately they are not the same: Oracle does not support
>>> INFORMATION_SCHEMA

>> sorry, I expected so all mature databases support it.

> Yes, this is really hard to understand.

> I would assume creating the INFORMATION_SCHEMA views based on the existing Oracle views is just a matter of maybe 3-4
daysof days work. So it is really not understandable that Oracle does not support this.
 

> But then they probably don't care - after all it's Oracle.

No, from their point of view it would be actively damaging: providing
standardized views would reduce customer lock-in, by making applications
more portable to other DBMSes.  The pain the OP is feeling is a
marketing advantage, so far as Oracle is concerned.
        regards, tom lane


Re: Oracle Equivalent queries in Postgres

From
bricklen
Date:
On Wed, Feb 16, 2011 at 2:42 AM, Sivannarayanreddy <sivannarayanreddy@subexworld.com> wrote:
Hello,
I am checking the compatibility of my product with Postgres database and i stucked in forming the below oracle equivalent queries in Postgres database, Could some one help me pleaseee



There is a sourceforge project that attempts to port the information_schema to Oracle, though I haven't tried it.

http://sourceforge.net/projects/ora-info-schema/