Advertisement
asanchez75

Linux/postgresql/sql

Jun 27th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1.  
  2. #####################################################################################################################
  3. Alter ALL tables OWNER TO myuser
  4. #####################################################################################################################
  5. https://resetroot.wordpress.com/2010/11/15/postgresql-alter-all-tables-to-user-myuser/#comment-74
  6.  
  7. 1) CREATE LANGUAGE plpgsql database_name
  8.  
  9. 2) create function execute(text) returns void as $BODY$BEGIN execute $1; END;$BODY$ language plpgsql;
  10.  
  11. 3) select execute(‘ALTER TABLE ‘ || table_name || ‘ OWNER TO condesan;’) from information_schema.tables where table_schema = ‘public’
  12.  
  13. #####################################################################################################################
  14. add or create a user account and grant permission for database
  15. #####################################################################################################################
  16. http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/
  17. //create database, user and assign user to database
  18. postgres=# create database jerry
  19. postgres=# create user tom with password 'admin';
  20. postgres=#GRANT ALL PRIVILEGES ON DATABASE jerry to tom;
  21. postgres=# alter database jerry owner to tom;
  22.  
  23. #####################################################################################################################
  24. alter table to implemente secuence
  25. #####################################################################################################################
  26.  
  27. CREATE SEQUENCE seq_glo_sitios_sit_secuencial;
  28. SELECT setval('seq_glo_sitios_sit_secuencial', max(sit_secuencial)) FROM glo_sitios;
  29. ALTER TABLE glo_sitios ALTER COLUMN sit_secuencial SET DEFAULT nextval('seq_glo_sitios_sit_secuencial');
  30.  
  31. //to this table
  32. CREATE TABLE glo_sitios
  33. (
  34. sit_secuencial bigint NOT NULL, -- autoincremental
  35. sit_pais character varying(255) NOT NULL DEFAULT ''::character varying, -- pais
  36. sit_nombresitiopiloto character varying(60) NOT NULL DEFAULT ''::character varying, -- sitio piloto
  37. sit_codsitio character varying(20) NOT NULL DEFAULT ''::character varying, -- codigo de sitio
  38. sit_codigo character varying(20) NOT NULL DEFAULT ''::character varying, -- codigo
  39. sit_ubicacionpolitica character varying(100) NOT NULL DEFAULT ''::character varying, -- autoincremental
  40. sit_codpais character varying(20) NOT NULL DEFAULT ''::character varying, -- codigo de pais
  41. sit_x numeric(10,6), -- coordenada x del sitio
  42. sit_y numeric(10,6), -- coordenada y del sitio
  43. CONSTRAINT glo_sitios_pkey PRIMARY KEY (sit_secuencial),
  44. CONSTRAINT glo_sitios_sit_secuencial_check CHECK (sit_secuencial >= 0)
  45. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement