Is there any way to list all schema in informix (including the ones which donot have any tables and any privileges)? - informix

I am trying to fetch metadata in my application. For that, I need to list all schemas and their metadata in informix. I am not able to find any system table which will list all schemas (as in oracle).
I saw this question but couldn't get desired result.
Have referred to informix's official website for systables and sysusers
select username,usertype from sysusers;
-- fetches users or roles with database level privileges
select distinct owner from systables;
-- fetches schemas containing a database object.
Also, what exactly is present in sysmaster database's systables and sysusers? When to use them?

There is no actual schema object in an Informix database ( you cannot grant privileges on a schema ). There are various types of "objects" and each object has an owner. You could consider that the owner is the schema, if you really want to. Doing a simple search on the catalog tables on a newly created Informix ( version 14.10.FC1 ) database we get:
SELECT
t.tabname,
c.colname
FROM
systables AS t
INNER JOIN
syscolumns AS c
ON
t.tabid = c.tabid
WHERE
c.colname = 'owner'
;
tabname systables
tabname sysindices
tabname syssynonyms
tabname syssyntable
tabname sysconstraints
tabname sysprocedures
tabname sysopclstr
tabname systriggers
tabname sysobjstate
tabname sysxtdtypes
tabname syscasts
tabname sysopclasses
tabname sysaggregates
tabname sysdomains
tabname sysindexes
And there can be more, this was just a quick look at the catalog tables. So your schema information is spread over multiple catalogs.
About the sysmaster database, it is a database ( although a special one ) and therefore it has it's own catalogs tables, just like any other Informix database.

Related

How to fix DF-JOIN-002 Error in Azure Data Factory (Only two Join conditions allowed)

I have a data flow with a Union on two tables then joining the results of the Union to another table. I keep receiving the following error when I try debugging the pipeline or previewing the data.
DF-JOIN-002 at Join 'Join1'(Line 40/Col 26): Only 2 join condition(s) allowed
I'm basically trying to build a pipeline to automate this query:
SELECT DISTINCT k.acct_id, s.Id, Email, FirstName, LastName FROM table_3 s
INNER JOIN
( (SELECT acct_id, event_date FROM table_1)
UNION (SELECT acct_id, event_date FROM table_2)) k
ON k.acct_id = s.Archtics_acct_id__c
WHERE event_date = 'xxxx-xx-xx'
enter image description here
I figured it out after some time. I had to delete the Join activity and add it again. It was still linked to another source. Even though only two sources were selected in the join settings

Db2 joining sysibm.systables to sysibm.syscolumns

when joining sysibm.systables to sysibm.syscolumns what are the best keys to use? accessesing db2 through sql server 2014 openquery
select a.name table_name, b.name column_name
from openquery(dw,'
select *
from sysibm.systables a
inner join sysibm.syscolumns b on ...
with ur');
It depends on DB2 platform you use.
DB2 for Z/OS catalog tables
Db2 for i catalog views
Db2 for LUW Catalog views
-- Db2 for LUW & DB2 for Z/OS
SELECT *
FROM SYSIBM.SYSTABLES T
JOIN SYSIBM.SYSCOLUMNS C ON C.TBCREATOR = T.CREATOR AND C.TBNAME = T.NAME;
-- Db2 for LUW
SELECT *
FROM SYSCAT.TABLES T
JOIN SYSCAT.COLUMNS C ON C.TABSCHEMA = T.TABSCHEMA AND C.TABNAME = T.TABNAME;
-- Db2 for IBM i
SELECT *
FROM QSYS2.SYSTABLES T
JOIN QSYS2.SYSCOLUMNS C ON C.TABLE_SCHEMA = T.TABLE_SCHEMA AND C.TABLE_NAME = T.TABLE_NAME;
Note about Db2 for LUW.
SYSIBM tables are not documented, but you may use the 1-st query above as well.
It's advisable to use SYSCAT views built on top of these SYSIBM tables instead.
If all you want is table name and column name, you don't need to even join to systables.
select table_schema, table_name, column_name
from syscolumns
If you really need to join, then table_schema, table_name would be the appropriate keys...
Note that I wouldn't use openquery(dw,'select * ...'), no sense in pulling back columns you aren't interested in.
This would be ok, select * from openquery(dw,'select table_name, column_name ...')

How to get the list of chunks of a table in informix?

I need to find which chunks occupied by a particular table in a informix database.
My current method is get the result from oncheck -pe dbspace command. But this task is very time consuming when that db-space has many chunks . I need to know is there any single query or quick way to list down the occupied chunks by extends for a particular table
The systabextents within the sysmaster database can be used to determine the chunks associated with a table. An example query:
select distinct te_chunk
from sysmaster:systabextents
where te_partnum != 0 and te_partnum in
(select partnum from systables where tabname = "<table>"
union
select partn from sysfragments f, systables t
where f.tabid = t.tabid and tabname = "<table>"
);
The first part of the union subquery will deal with tables that are not fragmented whilst the second part deals with index partitions and fragmented tables.
To get the chunk path name instead of number this query can be used:
select distinct c.fname
from sysmaster:systabextents te, sysmaster:syschunks c
where te.te_chunk = c.chknum
and te_partnum != 0 and te_partnum in
(select partnum from systables where tabname = "<table>"
union
select partn from sysfragments f, systables t
where f.tabid = t.tabid and tabname = "<table>"
);

How to get the size of a informix table?

I need to find out how much disk space occupied by a given table. How to see it? Suppose i have a table called tb1. Suppose it is currently using 1000 2kb pages. Then table size should be given as 2000kb.
To add to Jonathan's comment if the table does not store data in blob spaces or smart blob spaces then the oncheck -pt command will give the required information. Look at the "Pagesize" and "Number of pages allocated" information for each fragment.
You can also get this information in SQL with a query such as:
select sum(pagesize * nptotal)
from sysmaster:sysptnhdr
where partnum in
( select partnum from systables
where tabname = '<table name>'
union
select partn from sysfragments f, systables t
where f.tabid = t.tabid
and t.tabname = '<table name>' );

How to get last inserted record Id in Gupta SQL Base

I am new to Gupta Sql Base. I would like to know how to get the last inserted record in Gupta SQL
If you are using SYSDBSequence.NextVal to generate your Primary Key, either within the Insert stmt, or prior to the Insert , then you can retrieve it back immediately after the Insert by Selecting Where [Primary Key] = SYSDBSequence.Currval e.g.
Select Name from Patient Where Patient_Id = SYSDBSequence.Currval
Alternatively, If your Primary Key column has been defined as AUTO_INCREMENT , you can select it back after the Insert using MAX( [Primary Key ] ) e.g.
Select Name from Patient Where Patient_Id = (Select MAX( Patient_Id) from Patient )
Alternatively, if none of the above, then write an Insert Trigger to either return it , or to store the PK in a table so you will always have the latest PK recorded for you.
You may like to join the Gupta users forum at enter link description here or there is much archived information at enter link description here

Resources