Is there an easy way to compare to odoo (SaaS version) databases/instances in terms of added/changed custom fields?
Downloading databases gigabytes of database dumps and try to compare there seems to be to much effort
You can fetch the ir_model_fields table.
For example :
select * from ir_model_fields where model='stock.picking';
+----+--------+-------------+-------------+-----------------+--------------+--------+-----------------+----+--------+---------+-----+-------------------+--------+--------+-----+---------+----+-----+---------+------+----------+--------------+-------+-------+-------+-------+-----+----------+-----------+---------+----------+----------------------+----------------+
|id |name |complete_name|model |relation |relation_field|model_id|field_description|help|ttype |selection|copy |related |required|readonly|index|translate|size|state|on_delete|domain|selectable|relation_table|column1|column2|compute|depends|store|create_uid|create_date|write_uid|write_date|serialization_field_id|track_visibility|
+----+--------+-------------+-------------+-----------------+--------------+--------+-----------------+----+--------+---------+-----+-------------------+--------+--------+-----+---------+----+-----+---------+------+----------+--------------+-------+-------+-------+-------+-----+----------+-----------+---------+----------+----------------------+----------------+
|5709|name |NULL |stock.picking|NULL |NULL |335 |Reference |NULL|char |NULL |false|NULL |false |false |true |false |NULL|base |NULL |NULL |true |NULL |NULL |NULL |NULL |NULL |true |NULL |NULL |NULL |NULL |NULL |NULL |
|5715|group_id|NULL |stock.picking|procurement.group|NULL |335 |Procurement Group|NULL|many2one|NULL |false|move_lines.group_id|false |true |false|false |NULL|base |set null |NULL |true |NULL |NULL |NULL |NULL |NULL |true |NULL |NULL |NULL |NULL |NULL |NULL |
+----+--------+-------------+-------------+-----------------+--------------+--------+-----------------+----+--------+---------+-----+-------------------+--------+--------+-----+---------+----+-----+---------+------+----------+--------------+-------+-------+-------+-------+-----+----------+-----------+---------+----------+----------------------+----------------+
Related
I've been trying to find a solution to this since some days ago. I have the following dataset.
|id|order|certain_event|order_of_occurrence|
|--|-----|-------------|-------------------|
|a |1 |NULL |NULL |
|a |2 |NULL |NULL |
|a |3 |NULL |NULL |
|a |4 |NULL |NULL |
|a |5 |4 |1 |
|a |6 |NULL |NULL |
|a |7 |NULL |NULL |
|a |8 |4 |2 |
|a |9 |NULL |NULL |
The desired output consists in replacing the null values from the order_of_occurrence column with the next non-null value. Like this:
|id|order|certain_event|order_of_occurrence|
|--|-----|-------------|-------------------|
|a |1 |NULL |1 |
|a |2 |NULL |1 |
|a |3 |NULL |1 |
|a |4 |NULL |1 |
|a |5 |4 |1 |
|a |6 |NULL |2 |
|a |7 |NULL |2 |
|a |8 |4 |2 |
|a |9 |NULL |NULL |
I've tried using a subquery for retrieving the non-null values from the order of occurrence column, but I get more than one value returned. Like the following:
SELECT a.*,
CASE
WHEN a.order_of_occurrence IS NOT NULL THEN a.order_of_occurence
WHEN a.order_of_occurence IS NULL THEN (SELECT B.ORDER_OF_OCCURENCE FROM dataset AS B
WHERE B.ORDER_OF_OCCURRENCE IS NOT NULL)
END AS corrected_order
FROM dataset AS a
Thanks!
This is a simple task for the IGNORE NULLS option in FIRST/LAST_VALUE:
last_value(order_of_occurrence IGNORE NULLS)
over (partition by id
order by "order" DESC
rows unbounded preceding)
I have following data in my SEQUENCE_NUMBER table:
NUMBER |BUSINESS_VALUE|TEMP_V|SEQUENCE_NUMBER
123 |10 |10 |1
123 |20 |20 |2
123 |30 |30 |4
234 |40 |50 |1
I would like to transform the data as following:
NUMBER|VALUE_1|VALUE_2|VALUE_3|VALUE_4|TEMP_1|TEMP_2|TEMP_3|TEMP_4
123 |10 |20 |NULL |30 |10 |20 |NULL |30
234 |40 |NULL |NULL |NULL |50 |NULL |NULL |NULL
So based on SEQUENCE_NUMBER I am deciding which column number should be used during inserting to other table.
Do you know how can I perform this kind of a "merge"/"linearising" operation in SQL?
If you have a known (or maximum) number of values, and don't want to DYNAMIC
The subquery will UNPIVOT your source data
Example
Select *
From (
Select A.[NUMBER]
,B.*
From YourTable A
Cross Apply (
values (concat('Value_',[SEQUENCE_NUMBER]),[BUSINESS_VALUE])
,(concat('Temp_',[SEQUENCE_NUMBER]),[TEMP_V])
) B(Item,Value)
) src
Pivot (max(Value) for Item in ([VALUE_1],[VALUE_2],[VALUE_3],[VALUE_4],[TEMP_1],[TEMP_2],[TEMP_3],[TEMP_4]))pvt
Returns
Is there a word/phrase that describes the following action?
Where data in the form:
ID |Group |Type |Data
------------------------
1 |A |a |10
2 |A |b |11
3 |A |c |12
4 |B |a |20
5 |B |d |40
6 |C |b |31
Is transformed to this form:
Type |A |B |C (etc.)
-------------------------
a |10 |20 |NULL
b |11 |NULL |31
c |12 |NULL |NULL
d |NULL |40 |NULL
This is a kind of pivot, but where there is no summarising so data could (in theory) be updated via the transformed table.
I would have thought that this is needed quite widely for allocation of resources/stock to multiple projects. In the example above 'Group' would be project, 'Type' would be the resource and 'Data' would be the quantity needed or allocated.
I really want to ask a question about how this is normally approached in database design, but I need to know the terminology before I can do that!
I have self referential table like this:
id |level | parent_id
----------------------
1 |1 |null
2 |1 |null
3 |2 |1
4 |2 |1
5 |2 |2
6 |3 |5
7 |3 |3
8 |4 |7
9 |4 |6
------------------------
I need nth level parent in result. for example 2nd level parent
id |level | parent_id| second_level_parent_id
------------------------------------------------
1 |1 |null |null
2 |1 |null |null
3 |2 |1 |null
4 |2 |1 |null
5 |2 |2 |null
6 |3 |5 |5
7 |3 |3 |3
8 |4 |7 |3
9 |4 |6 |5
-------------------------------------------------
this works for me.
SELECT m.*,
CONNECT_BY_ROOT id AS second_level_parent_id
FROM my_table m
WHERE CONNECT_BY_ROOT level =2
CONNECT BY prior id = parent_id;
thanks #Jozef DĂșc
The sequence:
table1
=====
id - Description
----------------
|1 |Proj-x
|2 |Settlers
|3 |Bank
|4 |Newiest
table2
=====
id table1Id value alternate-value
---------------------------------
|1| 1 |12 |null
|1| 4 |6 | null
|1| null |22 |Desktop
|2| 2 |7 |null
|2| 3 |11 |null
|2| null |2 |Camby Jere
|3| 1 |8 |null
|3| 4 |6 |null
|3| null |7 |Camby Jere
The select instruction must return
|table1.id|Proj-x|Settlers|Bank |Newiest|Desktop|Camby Jere
----------------------------------------------------------
|1 |12 |null |null |null |null |null
|1 |null |null |6 |null |null |null
|1 |null |null |null |null |22 |null
|2 |null |7 |null |null |null |null
|2 |null |null |11 |null |null |null
|2 |null |null |null |null |null |2
|3 |8 |null |null |null |null |null
|3 |null |null |null |6 |null |null
|3 |null |null |null |null |null |7
The columns are description from table1 when id exists in table2 or the column "alternate-value" when table1Id is null.
Is it possible? Or do I need construct the query dynamically?
Well, yes, it is possible (if done in two steps), but it is a bit complex so I'm not certain whether you should do it. First, you could execute the following select:
with tmp1(MyFieldName) as
(select distinct coalesce(t2.alternate_value, t1.Description)
from table2 t2
left join table1 t1 on t2.Table1ID = t1.id),
tmp2(MyPivotSource) as
(select 'iif(coalesce(t2.alternate_value, t1.Description) = '''||MyFieldName||''', t2.MyValue, 0) as "'||MyFieldName||'"'
from tmp1)
select 'select t2.id as "table1.id", '||list(MyPivotSource)||'from table2 t2
left join table1 t1 on t2.Table1ID = t1.id'
from rdb$database
cross join tmp2
And then you would have to run the result. Note that I used MyValue rather than Value and that the columns may not appear in the order you desire (although that could also be possible).
Pivottables are not something that easily converts to SQL in Firebird and I generally prefer to create Pivot tables in Excel rather than Firebird, but as you can see it is possible.