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 t(i INT, b INT, c INT NOT NULL)
CREATE TABLE
SELECT *
FROM t
i | b | c |
---|
SELECT 0
SELECT format('ALTER TABLE %I ' || STRING_AGG(format('ALTER COLUMN %I SET NOT NULL', COLUMN_NAME), CHR(13) || ',')
, MIN(TABLE_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 't'
AND IS_NULLABLE = 'YES'
format |
---|
ALTER TABLE t ALTER COLUMN i SET NOT NULL ,ALTER COLUMN b SET NOT NULL |
SELECT 1
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 't'
table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | character_maximum_length | character_octet_length | numeric_precision | numeric_precision_radix | numeric_scale | datetime_precision | interval_type | interval_precision | character_set_catalog | character_set_schema | character_set_name | collation_catalog | collation_schema | collation_name | domain_catalog | domain_schema | domain_name | udt_catalog | udt_schema | udt_name | scope_catalog | scope_schema | scope_name | maximum_cardinality | dtd_identifier | is_self_referencing | is_identity | identity_generation | identity_start | identity_increment | identity_maximum | identity_minimum | identity_cycle | is_generated | generation_expression | is_updatable |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
db_1900259348 | public | t | i | 1 | null | YES | integer | null | null | 32 | 2 | 0 | null | null | null | null | null | null | null | null | null | null | null | null | db_1900259348 | pg_catalog | int4 | null | null | null | null | 1 | NO | NO | null | null | null | null | null | NO | NEVER | null | YES |
db_1900259348 | public | t | b | 2 | null | YES | integer | null | null | 32 | 2 | 0 | null | null | null | null | null | null | null | null | null | null | null | null | db_1900259348 | pg_catalog | int4 | null | null | null | null | 2 | NO | NO | null | null | null | null | null | NO | NEVER | null | YES |
db_1900259348 | public | t | c | 3 | null | NO | integer | null | null | 32 | 2 | 0 | null | null | null | null | null | null | null | null | null | null | null | null | db_1900259348 | pg_catalog | int4 | null | null | null | null | 3 | NO | NO | null | null | null | null | null | NO | NEVER | null | YES |
SELECT 3