What is parent_left and parent_right columns on Odoo ERP database? - database

Does anyone know what is the usage of parent_left or parent_right columns in Odoo ERP database? As I can see there are already parent_id column which is useful. What I don't see usage for parent_left or parent_right. You can see them using below queries.
select * from stock_location;
select * from account_account
Thanks

The parent_left and parent_right are 2 special fields that are related
to the parent_id field. The purpose of those fields is to make queries
within the hierarchy execute efficiently: with parent_left and
parent_right, you can retrieve all the descendants of a node without
making recursive queries.
You must refer this link: https://answers.launchpad.net/openobject-server/+question/186704

Related

Is it possible to get the columns of few tables at once?

I'm interested in getting the structure of each table in my DB.
Currently I'm using: DESCRIBE TABLE table1.
However, this means I have to do a separate query for each table. Was wondering whether there is a query I can get the structure of several tables at once (and therefore saving me some queries)?
Thanks,
Nir.
You can use Account Usage/Information Schema view COLUMNS
https://docs.snowflake.com/en/sql-reference/account-usage/columns.html
Following article have a slight difference example of using COLUMNS view to create a select statement but it should give you an idea
https://community.snowflake.com/s/article/Select-columns-based-on-condition-in-Snowflake-using-Information-Schema-and-Stored-Procedure
You have a couple options:
you can use the COLUMNS view in the information schema
https://docs.snowflake.com/en/sql-reference/info-schema/columns.html
Note: The view only displays objects for which the current role for the session has been granted access privileges.
you can use the COLUMNS view in the account_usage share schema:
https://docs.snowflake.com/en/sql-reference/account-usage/columns.html
Note: this will show all the columns in all tables, will show deleted objects and such as well.
Also note, there is a delay in the data (latency could be as much as 90 minutes, typically isn't though)

Is there a way to view the relationships of just one column in Oracle SQL Developer?

I´m quite new to the Oracle SQL Developer. I try to handle a big database and I need to define views. Therefore, I need the relationships of some tables. with the relational models of the Browser, I´m able to show ALL relationships of the table, which is quite confusing.
Is there a way to show the ralationships of just one column?
I want to pick the table and the column and I want to see to which other tables the column is connected.
Thank you.
My suggestion:
First find out in which tables the column name has been used :
select * from all_tab_columns where column_name='COLUMN_NAME';
And then you can see constraints defined for the respective columns in that tables

Difference between dba_segments and dba_users when trying to identify list of schema in Oracle DB

I am trying to figure out the list schema created in a database, I came across many answers like this and this which are trying to tell either use dba_segments or use dba_users.
But when I use those in my database then results have substantial difference.
I am looking for answers explaining which one is correct (dba_segments or dba_users) and why, so please do not think that my question is "how to get a list of all available schema in database".
dba_segments shows SEGMENTS - which are owned by schemas
you can have a schema that has no segments - objects that use segments can generally be thought of as tables or indexes. A user could own a synonym or a PL/SQL unit but have no segments for example.
Here's a list of segment types for my 12c system
HR#orcl🍻🍺 >select distinct segment_type from dba_segments;
SEGMENT_TYPE
LOBINDEX
INDEX PARTITION
ROLLBACK
NESTED TABLE
TABLE PARTITION
LOB PARTITION
LOBSEGMENT
INDEX
TABLE
CLUSTER
dba_users will show you EVERY user in the database, whether they own 'data' or not
here's how to find SCHEMAS with no segments, or one way
HR#orcl🍻🍺 >select distinct username
2 from dba_users
3 minus
4 select distinct owner
5 from dba_segments;
USERNAME
ANONYMOUS
APEX_LISTENER
APEX_PUBLIC_USER
APEX_REST_PUBLIC_USER
APPQOSSYS
BASIC_PRIVS
BI...

find the instance makes two queries different

Given any schema of a database and any two queries regarding this database, try to find the smallest instance that causes the two queries having different result sets.
I can only come up with an idea of how to find the difference between two queries, i.e. treat the result of each query as a subtable and compare the two tables to see if they are the same. Yet I am not sure whether this will work or not
have no clue about how to find the smallest instance, can anyone give me some hint or inspiration?
should I start to construct the instance making use of the info from the two queries or from the schema of the database or I am heading the wrong direction?
Thanks a lot!
update1: database instance is a scenario in which each table of the database has some specific values for its attributes.
for instance,
schema:
table A: attr1 attr2... table B: attr1 attr2 attr3 ...
I have to find in what scenario of the database that two arbitrary queries will return different results?
Assuming that you are using SQL Server, I believe that you want to see the difference of two results from two queires.
Use EXCEPT like this
SELECT * FROM table1
EXCEPT
SELECT * FROM table2

How to create column names/descriptors programmatically

In SQL Server given a Table/View how can you generate a definition of the Table/View in the form:
C1 int,
C2 varchar(20),
C3 double
The information required to do it is contained in the meta-tables of SQL Server but is there a standard script / IDE faciltity to output the data contained there in the form described above ?.
For the curious I want this as I have to maintain a number of SP's which contain Table objects (that is a form of temporary table used by SQL Server). The Table objects need to match the definition of Tables or Views already in the database - it would make life a lot easier if these definitions could be generated automatically.
Here is an example of listing the names and types of columns in a table:
select
COLUMN_NAME,
COLUMN_DEFAULT,
IS_NULLABLE,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION,
NUMERIC_SCALE
from
INFORMATION_SCHEMA.COLUMNS
where
TABLE_NAME = 'YOUR_TABLE_NAME_HERE'
order by
Ordinal_Position
Generating DDL from that information is more difficult. There seems to be some suggestions at SQLTeam
If you want to duplpicate a table definition you could use:
select top 0
*
into
newtable
from
mytable
Edit: Sorry, just re-read your question, and realised this might not answer it. Could you be clear on what you are after, do you want an exact duplicate of the table definition, or a table that contains information about the tables definition?
Thanks for your replies. Yes I do want an exact duplicate of the DDL but I've realised I misstated exactly what I needed. It's DDL which will create a temporary table which will match the columns of a view.
I realised this in looking at Duckworths suggestion - which is good but unfortunately doesn't cover the case of a view.
SELECT VIEWDEFINITION FROM
INFORMATIONSCHEMA.VIEWS
... will give you a list of columns in a view and (assuming that all columns in the view are derived directly from a table) it should then be possible to use an amended version of Duckworths suggestion to pull together the relevant DLL.
I'm just amazed it's not easier ! I was expecting someone to tell me that there was a well established routine to do this given the TABLE objects need to have all columns full defined (rather than the way Oracle does it which is to say - "give me something which looks like table X".
Anyway thanks again for help and any further suggestions welcomed.
In this posting to another question I've got a DB reverse engineering script that will do tables, views, PK, UK and index definitions and foreign keys. This one is for SQL Server 2005 and is a port of one I originally wrote for SQL Server 2000. If you need a SQL Server 2000 version add a comment to this post and I'll post it up here.

Resources