cartodb-postgresql/sql/test_ddl_triggers.sql

124 lines
2.7 KiB
MySQL
Raw Normal View History

\set VERBOSITY terse
-- Create a stub cdb_invalidate_varnish function if not available
--CREATE FUNCTION tmp() returns void AS $$
DO $$
BEGIN
PERFORM cdb_invalidate_varnish(0);
EXCEPTION
WHEN undefined_function THEN
2014-05-05 18:20:38 +08:00
CREATE OR REPLACE FUNCTION cartodb.cdb_invalidate_varnish(tabname text)
RETURNS void AS '' LANGUAGE 'sql';
END;
$$ LANGUAGE 'plpgsql';
--SELECT tmp();
create schema c;
CREATE USER cartodb_postgresql_unpriv_user;
GRANT ALL ON SCHEMA c to cartodb_postgresql_unpriv_user;
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
--SELECT session_user, current_user;
2014-05-05 18:20:38 +08:00
----------------------
-- CREATE TABLE
----------------------
select 1 as i INTO c.t3;
2014-05-05 18:20:38 +08:00
select
cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s",
the_geom, the_geom_webmercator,
i
from c.t3;
select
tabname::text,
round(extract('secs' from now() - updated_at)) as age
FROM CDB_TableMetadata;
----------------------------
-- ALTER TABLE RENAME COLUMN
----------------------------
select pg_sleep(.1);
alter table c.t3 rename column the_geom_webmercator to webmerc;
2014-05-05 18:20:38 +08:00
select
cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s",
the_geom, the_geom_webmercator,
i, webmerc
from c.t3;
select
tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs
2014-05-05 18:20:38 +08:00
FROM CDB_TableMetadata;
select pg_sleep(.1);
alter table c.t3 rename column the_geom_webmercator to webmerc2;
2014-05-05 18:20:38 +08:00
select
cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s",
the_geom, the_geom_webmercator,
i, webmerc, webmerc2
from c.t3;
select
tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs
2014-05-05 18:20:38 +08:00
FROM CDB_TableMetadata;
----------------------------
-- ALTER TABLE DROP COLUMN
----------------------------
select pg_sleep(.1);
alter table c.t3 drop column the_geom_webmercator;
2014-05-05 18:20:38 +08:00
select
cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s",
the_geom, the_geom_webmercator,
i, webmerc, webmerc2
from c.t3;
select
tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs
2014-05-05 18:20:38 +08:00
FROM CDB_TableMetadata;
----------------------------
-- ALTER TABLE ADD COLUMN
----------------------------
select pg_sleep(.1);
alter table c.t3 add column id2 int;
2014-05-05 18:20:38 +08:00
select
cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s",
the_geom, the_geom_webmercator,
i, webmerc, webmerc2, id2
from c.t3;
select
tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs
2014-05-05 18:20:38 +08:00
FROM CDB_TableMetadata;
----------------------------
-- DROP TABLE
----------------------------
RESET SESSION AUTHORIZATION;
drop schema c cascade;
2014-05-05 18:20:38 +08:00
select count(*) from CDB_TableMetadata;
DROP USER cartodb_postgresql_unpriv_user;