I would like to transfer most of my code written on T-SQL to Python, and came across basic data problems that could not be solved by searching in the SQLAlchemy documentation and in other forums.
Question:
How can I implement the following query options with SQLAlchemy (example for the test - below)?
select a.field1, a.field2, b.field2 from server1.database1.schema1.table_a as a inner server2.database1.schema1.table_b as b on a.fileld1 = b.fileld1
select a.field1, a.field2, b.field2 from server1.database1.schema1.table_a as a inner dataset_variable (**) as b on a.fileld1 = b.fileld1
The result of the query - print (select) (see below in the test case) returns an error: sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42S02', "[42S02] [M icrosoft] [ODBC SQL Server Driver] [SQL Server] Invalid object name 'server2.database1schema1.table_b'.
** Data received from another SQLAlchemy session (server2.database1.schema1.table_b) and stored in the variable dataset_variable
Test connection example: Two linked sql servers are used.
public int[] solution(String S, int[] P, int[] Q){
int[] result = new int[P.length];
int[] factor1 = new int[S.length()];
int[] factor2 = new int[S.length()];
int[] factor3 = new int[S.length()];
int[] factor4 = new int[S.length()];
int factor1Sum = 0;
int factor2Sum = 0;
int factor3Sum = 0;
int factor4Sum = 0;
for(int i=0; i<S.length(); i++){
switch (S.charAt(i)) {
case 'A':
factor1Sum++;
break;
case 'C':
factor2Sum++;
break;
case 'G':
factor3Sum++;
break;
case 'T':
factor4Sum++;
break;
default:
break;
}
factor1[i] = factor1Sum;
factor2[i] = factor2Sum;
factor3[i] = factor3Sum;
factor4[i] = factor4Sum;
}
for(int i=0; i<P.length; i++){
int start = P[i];
int end = Q[i];
if(start == 0){
if(factor1[end] > 0){
result[i] = 1;
}else if(factor2[end] > 0){
result[i] = 2;
}else if(factor3[end] > 0){
result[i] = 3;
}else{
result[i] = 4;
}
}else{
if(factor1[end] > factor1[start-1]){
result[i] = 1;
}else if(factor2[end] > factor2[start-1]){
result[i] = 2;
}else if(factor3[end] > factor3[start-1]){
result[i] = 3;
}else{
result[i] = 4;
}
}
}
return result;
}