-- #7169 matriz: DROP ATTRIBUTE / DROP COLUMN sobre un tipo compuesto cuyo -- valor esta GUARDADO en algun lado. Por escenario: el DROP (OK o ERROR con -- SQLSTATE) y que devuelve DESPUES lo que estaba guardado. -- Cada escenario usa su propio tipo para no contaminar al siguiente. \set ON_ERROR_STOP off \set SHOW_CONTEXT never \pset footer off \pset tuples_only on \echo '--- N1 (Nikhil) columna de tabla + unique; ALTER TYPE DROP ATTRIBUTE' create type n1 as (a int, b int); create table tn1 (v n1); create unique index on tn1 (v); insert into tn1 values (row(1,2)::n1), (row(1,3)::n1); alter type n1 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo ' => POST count(distinct v) (era 2):' select count(distinct v) from tn1; \echo '--- N2 rowtype de tabla guardado en otra tabla; ALTER TABLE DROP COLUMN' create table rn2 (a int, b int); create table tn2 (v rn2); insert into tn2 values (row(1,2)::rn2), (row(1,3)::rn2); alter table rn2 drop column b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo ' => POST count(distinct v) (era 2):' select count(distinct v) from tn2; \echo '--- S1 vista con constante del tipo: (1,2) = (1,3)' create type s1 as (a int, b int); create view vs1 as select '(1,2)'::s1 = '(1,3)'::s1 as eq; alter type s1 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo ' => POST eq (era f):' select eq from vs1; \echo '--- S2 vista que muestra la constante como texto' create type s2 as (a int, b int); create view vs2 as select '(1,2)'::s2::text as t; alter type s2 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo ' => POST t (era (1,2)):' select t from vs2; \echo '--- S3 CHECK de una tabla int que compara constantes del tipo' create type s3 as (a int, b int); create table ts3 (i int check ('(1,2)'::s3 <> '(1,3)'::s3)); alter type s3 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo ' => POST insert into ts3 (antes se podia):' insert into ts3 values (1); \if :ERROR \echo ' insert ERROR' :LAST_ERROR_SQLSTATE \else \echo ' insert OK' \endif \echo '--- S4 DEFAULT con la constante como texto' create type s4 as (a int, b int); create table ts4 (t text default '(1,2)'::s4::text); alter type s4 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif insert into ts4 default values; \echo ' => POST default insertado (era (1,2)):' select t from ts4; \echo '--- S5 default de parametro de funcion' create type s5 as (a int, b int); create function fs5(x s5 default '(1,2)'::s5) returns text language sql as 'select x::text'; alter type s5 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo ' => POST fs5() (era (1,2)):' select fs5(); \echo '--- S6 rowtype de TABLA en una vista; ALTER TABLE DROP COLUMN' create table rs6 (a int, b int); create view vs6 as select '(1,2)'::rs6 = '(1,3)'::rs6 as eq; alter table rs6 drop column b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo ' => POST eq (era f):' select eq from vs6; \echo '--- C1 control: funcion que solo NOMBRA el tipo (sin constante)' create type c1 as (a int, b int); create function fc1(x c1) returns int language sql as 'select 1'; alter type c1 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif \echo '--- C2 control: vista con NULL del tipo (no hay imagen guardada)' create type c2 as (a int, b int); create view vc2 as select null::c2 as x; alter type c2 drop attribute b; \if :ERROR \echo ' => DROP ERROR' :LAST_ERROR_SQLSTATE \else \echo ' => DROP OK' \endif