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?.
-- ambiguous test
-- results in 1 either way
SELECT (SELECT 1)::int;
?column? |
---|
1 |
SELECT 1
-- results in 1 either way
SELECT EXISTS (SELECT 1)::int;
exists |
---|
1 |
SELECT 1
-- unambiguous tests
-- invalid!
SELECT (SELECT 'foo')::int;
ERROR: invalid input syntax for type integer: "foo"
-- valid!
SELECT EXISTS (SELECT 'foo')::int;
exists |
---|
1 |
SELECT 1
CREATE TABLE t (id int);
INSERT INTO t VALUES (66);
CREATE TABLE
INSERT 0 1
-- valid
SELECT (SELECT t FROM t LIMIT 1).id;
id |
---|
66 |
SELECT 1
-- invalid!
SELECT EXISTS (SELECT t FROM t LIMIT 1).id;
ERROR: syntax error at or near "." LINE 2: SELECT EXISTS (SELECT t FROM t LIMIT 1).id; ^