I am supposed to create metadata layer on top of two inventory databases, local DB1 and local DB2.
For each object (table name, column name, etc.) that is present in each local db, there should be three representations (in the same row in the metadata table):
a canonical representation(global level) for the object. This is a representation that identifies the object globally (see first column in the example table below).
a local representation for local DB1:it refers to the name of the column in local DB1 that represents that same object. Also we create another column in the metadata table to store the data type of that column in local DB1 (see columns 2 and 3 in example table below)
a local representation for local DB2: it refers to the name of the column in local DB2 that represents that same object. In addition, we need to store its data type in local DB2 (see columns 4 and 5 in example table below)
The metadata table contains the following columns:
Column 1: Contains the name of a field(canonical representation).
Column 2: Contains the corresponding name of the same field in DB1(local DB1 name)
Column 3: Contains the name of the data type of that field in DB1
Column 4: Contains a function stored as a string, that maps the canonical name to the DB1 name (if applicable)
Column 5: Contains the corresponding name (local DB2 name) of the same field in DB2
Column 6: Contains the data type of that field in DB2
column 7: Contains a function to map the canonical name to the DB2 name (if applicable)
How to use select query to display data of these local databases using this meta_data table.
Related
I'm using ora2pg to import an oracle db schema into a postgresql db schema. I configured all in the correct way and I'm able to dump the oracle dn into the postgresql db.
In the schema that I'm converting I have some columns number(1,0) that I need to convert as boolean in the pg schema.
At first I used this configuration
REPLACE_AS_BOOLEAN NUMBER:1
so every column with this type will be conmverted as boolean in the pg db.
The problem is that I have a column in the oracle schema defined as number(1,0). This column has to remain numeric and maintain the same type on the pg schema, so it hasn't to be converted as boolean.
This means that i changed the property in this manner
REPLACE_AS_BOOLEAN TABLE1:COLUMN1 TABLE2:COLUMN2 TABLE3:COLUMN3
I have a lot of columns that they have to be converted as boolean and the definition of this property became very long.
Is there a method to define the REPLACE_AS_BOOLEAN property to replace all the column with type number(1,0), but with some exception for one or some of them?
I had to wrote the property with the list of all the tables name and columns name
I have to find a table (or more than one) that contains a column named 'idRec' on a Firebird database.
You can query the RDB$RELATION_FIELDS table for this:
select RDB$RELATION_NAME
from RDB$RELATION_FIELDS
where RDB$FIELD_NAME = 'idRec'
This will only match columns that are actually called idRec (and thus are required to be quoted when used in SQL statements). If you are actually looking for a column called IDREC (unquoted object names are stored in uppercase), use where RDB$FIELD_NAME = 'IDREC'
I have created a model in Django.
class MyModel(models.Model):
features = TextField(blank=True, default='')
There are several possible ways to store the data in the feature field. Some examples below.
feature1;feature2
feature1, feature2
feature1,feature2
And so on. I created a GIN index for that field using migrations.RunSQL() (thanks to the following answer). The postgreSQL command looks as follows
CREATE INDEX features_search_idx ON "mymodel" USING gin (regexp_split_to_array("mymodel"."features", '[,;\\s]+'));
Now I need to check the size of the created index in my database. I tried to do it with the following commands
SELECT pg_size_pretty (pg_indexes_size("mymodel"."features_search_idx"));
SELECT pg_size_pretty(pg_indexes_size("features_search_idx")) FROM "mymodel";
The latter one failed with ERROR: column "features_search_idx" does not exist and the former one failed with ERROR: missing FROM-clause entry for table "mymodel".
How can I check the index size?
pg_indexes_size takes an argument of type regclass, that is an object ID that is represented as a string that is the object name. So if you don't supply an object ID, you have to supply a string (single quotes) that is the name of the table:
SELECT pg_size_pretty (pg_indexes_size('mymodel.features_search_idx'));
Microsoft's Database Objects documentation states that table names can only be 128 characters. Does this include the Schema name? What about the database name?
For example, if I needed to run the following sql statement that copies all data in a source table to a destination table in a different database, I'd write:
SELECT *
INTO DestinationDatabase.DestinationSchema.DestinationTable
FROM SourceDatabase.SourceSchema.SourceTable
Now say I have a table that stores the database name, schema name, and table name for both the source and the destination tables, what size limit should I put on the columns storing these names?
Is it a 128 character limit for each part (database name, schema name, table name) or should the entire identifier (like DestinationDatabase.DestinationSchema.DestinationTable) only be up to 128 characters long?
It's length of sysname data type nvarchar(128). It's per element (so for table separately 128).
Using DB2 v9.7 (windows), with an SMS tablespace.
Inside the tablespace folder are files for the various db objects.
Ex) SQL00003.IN1, SQL00003.DAT, etc..
How do I determine which database object corresponds to which file?
(for both indexes and tables)
The digits in the file name (i.e. 00003 = 3) correspond to the TABLEID column from SYSCAT.TABLES. Please note that TABLEID is unique only within a single tablespace, so you need to know what tablespace's container path you are looking at to make this correlation.
All table data is stored in the .DAT file.
All index data (for all indexes) is stored in the .INX file, regardless of how many indexes there are. (Note that it appears you have a typo in the filename SQL00003.IN1 above, this should be SQL00003.INX)
If your table has LOBs, then there will be 2 additional files with the same SQLxxxxx name: a .LBA and a .LB file.