Hello have the following problem: I have created a sequence in a trigger, and then dynamically instantiate it by create statements of tables in the same trigger. When I try to put NEXTVAL('secuencia')
the single quotes tell me the variable, which I can do in this case because they are necessary to be able to call the sequence:
Sequence
sql := 'CREATE SEQUENCE mod_riestadistica.sec_'||nombretabla||'_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
ALTER TABLE public.sec_'||nombretabla||'
OWNER TO postgres;';
execute sql;
sql := 'CREATE TABLE public.t_'||nombretabla||'('||nombre_id||' numeric NOT NULL DEFAULT NEXTVAL ("public"."sec_' || nombretabla||'"), CONSTRAINT pk_' ||nombretabla||' PRIMARY KEY ('||nombre_id||' ) )
WITH ( OIDS=FALSE); ALTER TABLE public.t_'||nombretabla||' OWNER TO postgres;';
execute sql;