postgresql – Create unique index on Postgres with any column combination

I have a companies table:

CREATE TABLE "companies" (
 "id" bigserial,
 "name" varchar(255) NOT NULL
 PRIMARY KEY ("id")
)

I want companies to have parents and childs. A company might have many parent and many child companies, so I created the following table:

CREATE TABLE "parent_companies" (
 "id" bigserial,
 "parent_company_id" bigint,
   CONSTRAINT "parent_companies_parent_company_id_fkey"
   FOREIGN KEY ("parent_company_id")
   REFERENCES "companies"("id"),
 "child_company_id" bigint,
   CONSTRAINT "parent_companies_child_company_id_fkey"
   FOREIGN KEY ("child_company_id")
   REFERENCES "companies"("id")
 PRIMARY KEY ("id")
)

I want parent and child to be unique, so I added the following constraint:

CREATE UNIQUE INDEX "parent_companies_parent_company_id_child_company_id_index" ON "parent_companies" ("parent_company_id", "child_company_id")

This will not allow the same parent and child to be created twice in the database. However, I would like to also prevent a child company being saved as a parent of its parent company. For example, I would to prevent this from happening:

-( RECORD 1 )-----+--------------------
id                | 1
parent_company_id | 1
child_company_id  | 2
-( RECORD 2 )-----+--------------------
id                | 2
parent_company_id | 2
child_company_id  | 1

Since in record 1 it’s defined that company 1 is the parent of company 2, I want a way of preventing company 2 being recorded as parent of company 1.

I thought it could be the case of using the EXCLUDE or the CHECK constraints, but I couldn’t figure out a way of making either work.

python 3.x – Mean difference calculator for any int combination

What it does

Calculates the mean difference for a list of any combination of ints (I think).

What I want to know

The only other way I can think of doing this is using recursion.

I’d like to know if there are other ways to do this.

Code:

nums = (3, 1, 2, 5, 1, 5, -7, 9, -8, -3, 3)

l = len(nums) - 1

diff_list = ()

for i in range(l):
    diff = nums(0) - nums(1)
    if diff < 0:
        diff = nums(1) - nums(0)
    print(diff)
    diff_list.append(diff)
    nums.pop(0)

mean = sum(diff_list)/len(diff_list)

print(round(mean, 1))

reference request – rank of a linear combination of matrices

Let $A_1,…, A_s in M_n(mathbb{R})$ be symmetric matrices and suppose they are linearly independent over $mathbb{R}$. This means that
$$
m = min_{(c_1, …, c_s) in mathbb{R}^s backslash {0}} rank( sum_{i=1}^s c_i A_i ) > 0
$$

I am interested in the question how large can $m$ be?
I am not sure where to start looking… if someone could point me to a good reference it’s very appreciated! Also any comments are appreciated!

polynomials – Find the combination in terms of the generating set for a specific element of the module

Consider we have already obtained the generating set $G={g_i}$ of a module $M$ in polynomial ring $R$, then, for a given element of the module, $x$, how to find the proper combination coefficient $a_i$, namely
$$x=a_1g_1+a_2g_2+cdots+a_mg_m .$$

I am not familiar with the ring theory either the module of syzygies.
But I am doing some practical calculations which involve the first module of syzygies.
For a given (multivariable) polynomial ring $R$, I understand that the first module of syzygies is related to the kernel of the following map
$$psi: R^4to R $$
$$c_1r_1+c_2r_2+c_3r_3+c_4r_4 mapsto r$$
where the l.h.s. of the map is defined by the module generated by a given number (say, four) polynomials $r_1,cdots,r_4$.
The generating set ${d_i}$ of the kernel of the above map can be derived through the Grobner basis of these polynomials, which can be obtained (without awareness of the details) by the Mathematica command
GroebnerBasis(). For the ideal generated by ${r_i}$, the command PolynomialReduce() seems to work.

For instance, I tried the follows

 gb = GroebnerBasis({y - xz, x - yz, 1 - y^2, 1 - x^2}, {x, y, z})
 PolynomialReduce(-1 + yz^2, gb, {x, y, z})

 {-1 + yz^2, -1 + xz^2, -xz + y, x - yz}
 {{1, 0, 0, 0}, 0}

But instead, I need to expand an element $x$ of the kernel in terms of the generating set ${d_i}$. It seems to be a basic task but I have no idea how it might work. Many thanks in advance!

google sheets – How to make variables dynamic in ARRAYFORMULA/QUERY Combination

Good day everyone,

I’m trying to self populate the first column of the “Main” sheet with a query that returns the first column of the “Finance Office” sheet that matches all three names.

I came up with this

=ARRAYFORMULA(IFS(ROW(A:A)=1,"Finance Office", B:B="","",TRUE,QUERY('Finance Office'!A1:K, "SELECT A WHERE A is not null AND C = '"&C2&"' AND D = '"&D2&"' AND E = '"&E2&"'",0)))

This matches the first row correctly and displays OK as it matches C with C2, D with D2 etc. But the succeeding rows does not auto increment the variables. How can I make the variables increment so that the next row should have C3, D3, and E3 as its variables? The next two rows should not have any matches since they have not been appended in the “Finance Office” sheet.

I’m asking this because I don’t want to drag down the formula for every new row that is added from the form. Dragging down works but I was hoping for an automated approach that’s why I’m using ARRAYFORMULA.

Included is a link to the spreadsheet.
https://docs.google.com/spreadsheets/d/1A8IOW3GntInTUd6uHkjegHPJELKzrhPmW9K4FBK_pks/edit?usp=sharing

Thanks and have a great day.

macos – Use Shift+Key combination in Teamviewer iPad –> OS X 10.15

I am connecting from iPad to a Mac running 10.15 and TeamViewer. Shift modifier works to input capital letters, but it does not when I give a key combination, such as Shift+Enter to evaluate cells in Mathematica. Command keys such as Cmd+S to save work instead.

I can issue Shift+Key using the menu in TeamViewer for special keys, but that is super annoying for programs such as Mathematica where you need to press Shift+Enter every time you want to compute anything.

How to get shift+key to work in TeamViewer using just the guest keyboard?

ubuntu – E: Command line option –enablerepo=nginx is not understood in combination with the other options

I am new programmer. and I am learning how use Jenkins with Docker in Ubuntu 20.04. Could you, please give me a help?

nginx.repo

sudo apt install curl gnupg2 ca-certificates lsb-release
echo “deb http://nginx.org/packages/ubuntu lsb_release -cs nginx”
| sudo tee /etc/apt/sources.list.d/nginx.list

echo “deb http://nginx.org/packages/mainline/ubuntu lsb_release -cs nginx”
| sudo tee /etc/apt/sources.list.d/nginx.list

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add –

sudo apt-key fingerprint ABF5BD827BD9BF62

sudo apt update
sudo apt install nginx

Dockerfile

FROM remote-host

COPY ./conf/nginx.repo /etc/apt.repos.d/nginx.repo

RUN
apt -y install nginx-1.12.2 openssl –enablerepo=nginx &&
apt -y install https://repo.ius.io/ius-release-el7.rpm &&
apt -y install
php71u-fpm
php71u-cli
php71u-mysqlnd
php71u-soap
php71u-xml
php71u-zip
php71u-json
php71u-mcrypt
php71u-mbstring
php71u-zip
php71u-gd
–enablerepo=ius-archive && apt clean all

EXPOSE 80 443

VOLUME /var/www/html /var/log/nginx /var/log/php-fpm /var/lib/php-fpm

COPY ./conf/nginx.conf /etc/nginx/conf.d/default.conf

COPY ./bin/start.sh /start.sh

RUN chmod +x /start.sh

CMD /start.sh

I can’t build de service with docker-compose build

Thanks