By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
CREATE TABLE customer (customer_id INTEGER, name VARCHAR(6), passworddisabled VARCHAR(5));
INSERT INTO customer (customer_id, name, passworddisabled) VALUES
('1', 'Pedro', FALSE),
('2', 'Sandra', FALSE),
('3', 'Peter', FALSE),
('4', 'Norman', FALSE);
CREATE TABLE loan (loan_id INTEGER, loan_customerid INTEGER, loan_cashregister INTEGER);
INSERT INTO loan (loan_id, loan_customerid, loan_cashregister) VALUES
('1', '1', '1'),
('2', '1', '1'),
('3', '4', '2'),
('4', '1', '1');
CREATE TABLE
INSERT 0 4
CREATE TABLE
INSERT 0 4
UPDATE customer AS c
SET passworddisabled = true
FROM loan AS l
WHERE c.customer_id = l.loan_customerid AND l.loan_cashregister = '1';
UPDATE 1
SELECT * FROM customer;
customer_id | name | passworddisabled |
---|---|---|
2 | Sandra | false |
3 | Peter | false |
4 | Norman | false |
1 | Pedro | true |
SELECT 4