Issue in pgloader in version postgres Version 14 - pgloader

Error - Pgloader 19 fell through ECASE expression wanted one of (0 2 3 4 5 6 7 8)
Current version - pgloder version 3.6.2
Postgres Version -14
It working in 12 version successfully

Related

Excel xlsx file modified into a dataframe is not recognized by an R package that uses dataframe

I uploaded an Excel xlsx file then created a dataframe by converting numeric variables into categories. When I run a R package that uses dataframe, the output shows the following error:
> library(DiallelAnalysisR)
> Griffing(Yield, Rep, Cross1, Cross2, GriffingData41, 4, 1)
Error in `$<-.data.frame`(`*tmp*`, "Trt", value = character(0)) :
replacement has 0 rows, data has 20
When I issue a str() function, it shows the modifications of the numeric columns into catergories as below.
> str(GriffingData41)
'data.frame': 20 obs. of 4 variables:
$ CROSS1: Factor w/ 4 levels "1","2","3","4": 1 1 1 1 2 2 2 3 3 4 ...
$ CROSS2: Factor w/ 4 levels "2","3","4","5": 1 2 3 4 2 3 4 3 4 4 ...
$ REP : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 2 ...
$ YIELD : num 11.9 14.5 9 13.5 20.5 9.8 16.5 22.1 18.4 19.4 ...
Is this a problem in my dataframe creation?
I would appreciate it if I could be helped with this error. By the way, I am running this in R Studio.
Thank you.
Note: This is not really a solution to my problem but I managed to move forward by saving my Excel data in CSV format; changing the data type of the specific columns to character and importing to R Studio. From there, creating the dataframe and running the R package went smoothly. Still, I am curious why it did not work on the "xlsx" file.

SQL: get variance for multiple columns without using PIVOT

I have a datatable (dt) like the following in SQL:
ID state_id act rd_1 rd_2 rd_3 rd_4 rd_5
11 abc,13.3 1 1. 31 17.4 32.4 0.4
11 afd,23.2 4 1. 42.1 1.3 31.9 0.39
11 dfw,154 7 0. 0.3 4.3 8.21 163.3
12 vab,64.5 8 1. 32.3 11 2.1 21.3
12 avf,542 2 0. 2.12 28.2 8.12 57.5
12 vjg,35 4 1. 5.7 8.64 7.46 0.25
13 vaw,424.2 4 1. 64.3 0.435 4.3 35.3
14 bda,243 1 0. 4.4 4.6 2.4 4.2
15 rbe,24.2 3 1. 43 53.5 4.4 8.5
I want to, for each row, calculate the variance of values from rd_1 to rd_5 (they are doubles). ID and state_id uniquely identifies a row. The desired output is the like the following:
ID state_id act rd_1 rd_2 rd_3 rd_4 rd_5. var_rd
11 abc,13.3 1 1. 31 17.4 32.4 0.4 192.6624
11 afd,23.2 4 1. 42.1 1.3 31.9 0.39 323.3181
11 dfw,154 7 0. 0.3 4.3 8.21 163.3 4109.9855
12 vab,64.5 8 1. 32.3 11 2.1 21.3 141.3463
13 vaw,424.2 4 1. 64.3 0.435 4.3 35.3 636.2333
14 bda,243 1 0. 4.4 4.6 2.4 4.2 3.0496
15 rbe,24.2 3 1. 43 53.5 4.4 8.5 473.2456
I know it is possible to use pivot to flatten the data and then calculate variance on column (rd_value) in the flattened data. But the SQL I use do not support Pivot method. I tried using UNION but it appears that it messes up with user_id.
I would approach this just by applying the formula for variance:
select t.*,
( (rd_1 - rd_avg) * (rd_1 - rd_avg) +
(rd_2 - rd_avg) * (rd_2 - rd_avg) +
(rd_3 - rd_avg) * (rd_3 - rd_avg) +
(rd_4 - rd_avg) * (rd_4 - rd_avg) +
(rd_5 - rd_avg) * (rd_5 - rd_avg) +
) as variance
from (select t.*,
(rd_1 + rd_2 + rd_3 + rd_4 + rd_5) / 5 as rd_avg
from t
) t

SQL Query to find and remove characters

I am importing data from a flat file to a SQL table called TCVS_tmp_PO_Detail using SSIS and SQL. Now and then I get some characters in the Purchase Order column that I would like to find and eliminate if they occur.
The characters are , so could I trim these 3 characters on the left of the number out? It does not occur all the time so I can run it on the front end of my SSIS job as a query to correct it before exporting it.
Here is an example of what it looks like when it occurs
Purchase Order
7
7
8
8
8
8
8
8
9
10
10
10
10
11
12
13
11
12
13
14
14
15
15
16
16
17
19
18
19
20
22
I'm not sure where the data lies for the processing, but you can easily do this with a case expression:
(case when purchase_order like '%' then stuff(purchase_order, 1, 3, '')
else purchase_order
end) as purchase_order
I suppose you use "Data Flow Task"
Add "Derived Column" component
Add new column
Add this code to the Expression
REPLACE(Purchase,"","")
The results:

5 numbers in an empty binary tree

You insert 5 numbers to an empty binary search tree. The numbers output from applying in-order scan algorithm to this tree are:
4 7 8 9 11
and the numbers output from applying level-order scan algorithm to the tree are
7 4 9 8 11
What is(are) leaf node value(s) in the tree after you delete node 4?
Now this will be a very rough sketch to do, but bear with me. So you gave me a field of numbers, and I'm just assuming 7 is the root. so it goes like this.
7
/ \
4 8
\
9
\
11
In this case, 4 and 11 would be the leaf nodes. Now after you delete 4 from it.
7
\
8
\
9
\
11
Leaving 11 to be the leaf since it has no children.

Auctions System Logical Condition

I am trying to make an auctions system but can not figure out the logical conditions for doing so..
Lets say that I have 10 credit
$credit
I have already bet 5 credits on another auction... so I owe 5 from 10 $owe
I thus have 5 available... $available = $credit - $owe (=5)
I bet 3 from available (on a different item)...
I wish to bet again 4 (cancel 3, update to 4), but credit available is now $available - 3 (=2)
Can't find a logical solution.... written in code.
What is the condition for setting a bet???
Made up a matrix with the dependence between variables:
bet available owe lastbet
1 10 10 0
2 9 11 1
3 7 13 2
4 4 16 3
5 0 20 4
6 -5 25 5
7 -11 31 6
8 -18 38 7
9 -26 46 8
10 -35 55 9
11 -45 65 10
Need to translate it into a condition statement.... (the next row would not meet the conditions)
The condition should fail on the 11th row....
Based on the Matrix... I found out that the condition is:
if ($bet <= (($owe + $available) / 2)) {}
Not very intuitive......