Compare a value against multiple columns in Postgres using Cube.js? - cube

I have a database that looks something like this image.
I have studies that can have multiple projects (1:M), and each project has a project type. Studies can also have assessments, and assessments can have 1 or more project types linked to them (M:N). I’m trying to create a dimension on Assessments that will check if the project type already exists in a specific project tied to that study.
Ex:
Study 1 has a project with project type “A”.
Study 1 has a project with project type “B”.
Study 1 has an assessment.
Assessment has project type “A”.
On assessment 1, “A” has the dimension already_exists as true.
This is what the dimension on Assessments looks like.
already_exists: {
type: ‘string’,
case: {
when: [
{sql: `${PactappProjecttype}.title IN (SELECT ${PactappProjecttype3}.title )`, label: “Exist” },
],
else: {label: “Doesnt Exist”}
}
},
However, when I run the query, it’s doing a “single” comparison of the project’s project_type, not on all of the project’s project_types. So I get two records, one where it says assessment 1 has already_exists as true (for the project that has project type “A”) and one where it says assessment 1 has already_exists as false (for the project that has project type “B”). How can I change my sql query to compare all of the study’s project’s project_types, and not just each project_type individually?

Related

How can I model a domain that include roles with several attributes?

I have read the documentation, and I am struggling with the following case (probably I am thinking in neo4j and hyperedges and that's why I can think clearly here):
Assume that I want to model the following entities: :person (with some attributes like :name, id, etc), :school (again some attributes) the relation ship of between the school and the person could be like :student or :teacher. And this could evolve through time (a :person could not be related to the school, later is a :student and much later maybe as a :teacher)
When the :person is a :student it will have an student-id, and as a :teacher it will have another id lets say teacher-id.
So, should I have:
:person/name 'John'
:school/id 'SCHOOL-1'
:student/name 'John'
:student/school 'SCHOOL-1'
? How I should include information as the student-id, What if there is more schools?
But now, it seems to me that the relationship between this entities is an hyperedge (that's why I mentioned neo4j). And I don't know what is the best way of modelling this is datomic.
Thanks in advance
I have a good example of using Datomic to keep track of James Bond and various villians available here. Everything is written in the form of unit tests using the Tupelo Datomic library so it is easy to verify the base project and any changes you have:
~/io.tupelo.demo/datomic > lct
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
lein test _bootstrap
-------------------------------
Clojure 1.10.1 Java 13
-------------------------------
lein test tst.tupelo.datomic.bond
Ran 2 tests containing 35 assertions.
0 failures, 0 errors.
The above will work with Datomic Free edition, so you don't even need a paid license to get started.
In the Bond example, the characters may have multiple weapons, which are modeled as a set:
; Create some antagonists and load them into the db. We can specify some of the
; attribute-value pairs at the time of creation, and add others later. Note that
; whenever we are adding multiple values for an attribute in a single step (e.g.
; :weapon/type), we must wrap all of the values in a set. Note that the set
; implies there can never be duplicate weapons for any one person. As before,
; we immediately commit the new entities into the DB.
(td/transact *conn*
(td/new-entity { :person/name "James Bond" :location "London" :weapon/type #{ :weapon/gun :weapon/wit } } )
(td/new-entity { :person/name "M" :location "London" :weapon/type #{ :weapon/gun :weapon/guile } } )
(td/new-entity { :person/name "Dr No" :location "Caribbean" :weapon/type :weapon/gun } ))

Lookup project task list an assign to project with yes/no (array vlookup?)

I would like to know if any of my projects (A,B,C or D) have ever been associated with certain tasks from another table.
For instance have project A ever been associated with 'pear' in any of the 'project tasks'
I would assume this would require a array formula to look across a long list of project and check if any project 'A* is associated with pear in a 'contain' manner?
Firstly, it may be possible that your tasks list includes words within words (using your fruit analogy, egAppleand Crabapple
Second, your Project Tasks list needs to be consistant (one choice of seperator, no spaces). So either clean it up manually, or write a formula to do it. Your choice of separator must not appear in in the task list (if you had a task do this, or that then comma wouldn't work) I'll demo the formula
Add a columnJ with this formula
=","&SUBSTITUTE(SUBSTITUTE(I2,";",",")," ","")&","
Add more Substitutes if needed
Then use this formula for the results
=COUNTIFS($H:$H,$A2,$J:$J,"*," & B$1 & ",*") > 0

SSDT How to: Deploy .dacpac ignoring drop columns on target

I'm using the Database project in Visual Studio.
In my scenario I have customers who intuitively customize the database I provide for them, e.g. adding some columns in existing tables, adding new tables...
How can I make when deploying .dacpac these objects that are not part of my schema are not excluded?
Important:
Set DropObjectsNotInSource=FALSE is not working for table columns.
EDIT
Ed, please see if I am doing something wrong:
using (DacPackage dacPackage = DacPackage.Load(DacPacFileName))
{
var dacServices = new DacServices(ConnectionString);
var dacOptions = new DacDeployOptions
{
AdditionalDeploymentContributorArguments = "SqlPackageFilter=KeepTableColumns(*)"
};
dacServices.Deploy(dacPackage, NomeBancoDados, true, dacOptions);
}
Is '*' in table filter "ALL TABLES" ?
I tried a table name too, but it did not work.
I wrote this for this scenario:
https://agilesqlclub.codeplex.com
You can "Keep" which deploys objects if they do not exist but does not deploy if there are changes or "Ignore" to completely ignore.
You can do this on type or name (regex)
Ed

Determining Difference Between Items On-Hand and Items Required per Project in Access 2003

I'm usually a PHP programmer, but I'm currently working on a project in MS Access 2003 and I'm a complete VBA newbie. I'm trying to do something that I could easily do in PHP but I have no idea how to do it in Access. The facts are as follows:
Tables and relevant fields:
tblItems: item_id, on_hand
tblProjects: project_id
tblProjectItems: project_id, item_id
Goal: Determine which projects I could potentially do, given the items on-hand.
I need to find a way to compare each project's required items against the items on-hand to determine if there are any items missing. If not, add the project to the list of potential projects. In PHP I would compare an array of on-hand items with an array of project items required, using the array_diff function; if no difference, add project_id to an array of potential projects.
For example, if...
$arrItemsOnHand = 1,3,4,5,6,8,10,11,15
$arrProjects[1] = 1,10
$arrProjects[2] = 8,9,12
$arrProjects[3] = 7,13
$arrProjects[4] = 1,3
$arrProjects[5] = 2,14
$arrProjects[6] = 2,5,8,10,11,15
$arrProjects[7] = 2,4,5,6,8,10,11,15
...the result should be:
$arrPotentialProjects = 1,4
Is there any way to do this in Access?
Consider a single query to reach your goal: "Determine which projects I could potentially do, given the items on-hand."
SELECT
pi.project_id,
Count(pi.item_id) AS NumberOfItems,
Sum(IIf(i.on_hand='yes', 1, 0)) AS NumberOnHand
FROM
tblProjectItems AS pi
INNER JOIN tblItems AS i
ON pi.item_id = i.item_id
GROUP BY pi.project_id
HAVING Count(pi.item_id) = Sum(IIf(i.on_hand='yes', 1, 0));
That query computes the number of required items for each project and the number of those items which are on hand.
When those two numbers don't match, that means at least one of the required items for that project is not on hand.
So the HAVING clause excludes those rows from the query result set, leaving only rows where the two numbers match --- those are the projects for which all required items are on hand.
I realize my description was not great. (Sorry.) I think it should make more sense if you run the query both with and without the HAVING clause ... and then read the description again.
Anyhow, if that query gives you what you need, I don't think you need VBA array handling for this. And if you can use that query as your form's RecordSource or as the RowSource for a list or combo box, you may not need VBA at all.

Entity relationship

I have started develping database for machineries performance mgt system
Facts:
1.A machine(platNo,model,name) can work on several cane fields(fieldNo,fieldNo)
- machine vs field
2.Many machineries can work on a cane field
3.A machine can do tasks for many userDept(deptId,deptName)
4.A userDept demands several machines for its activity{A task can be done on several cane fields; plowing,land shaping,etc can be done on field 1, 2, 3...- task vs field,
Many tasks can be done on a field; on field 1 , plowing ,harrowing,... can be done
- task vs field?/?}
5.A machine can do for many userDept; lpcd(using its machine) can do the same type of work (e.g.: plowing) for plantation, rehabilitation and expansion projects.
- task vs userDept
6.Much type of tasks can be done for a userDept; plowing, harrowing,... can be done for plantation- task vs user
7.A machine works in three shifts(1 -to- 3)
Problem : please help me in designing the ER!!
Thanks,
Dejene
I'll assume platNo can be used as a unique identifier for a machine. There are quite a few possibilities depending on rules that you have left ambiguous - e.g. some of the following relations may not be required or may need to be modified:
MACHINE (platNo, model, name) - represents each machine
FIELD (fieldNo) - represents each cane field
TASK (taskId, taskName) - represents the various tasks (e.g. plowing, harrowing) that can be done by any machine
USERDEPT (deptId, deptName) - represents each department
PROJECT (projId, projName, deptId) - represents each project for each department (e.g. plantation, rehabilitation, expansion)
SHIFT (shiftNo) - represents the shifts that any machine might be assigned to
MACHINE_FIELD (platNo, fieldNo) - represents the fact that a particular machine can work on a particular cane field
MACHINE_TASK (platNo, taskId) - represents the fact that a particular machine can perform a particular task
PROJECT_REQUIREMENT (projId, taskId) - represents the fact that a particular project (for a particular department) requires a particular task
MACHINE_ASSIGNMENT (projId, taskId, shiftNo, platNo) - represents the fact that a particular machine has been assigned to perform a particular task on a given shift

Resources