0

I'm trying to create a system, where I'm wanna sort the data for years (using schemas), for example now I have a schema named datos_2016 then I create a sequence named seq_datos.

When I try to create the table datos and set the sequence for cdata it says

"An error has ocurred: ERROR The relation "seq_data" doesn't exits"

But if I create the schema "public" and then create the sequence there, no error happens (the table is successfully created).

Why can't I create sequences in another schema?

The SQL CODE:

CREATE TABLE datos_2016.data
(
   cdata integer NOT NULL DEFAULT nextval('seq_data'), 
   CONSTRAINT fk_cdata PRIMARY KEY (cdata) USING INDEX TABLESPACE sistema_index
) 
WITH (
  OIDS = FALSE
)

TABLESPACE sistema_data;

The Sequence Code:

CREATE SEQUENCE datos_2016.seq_data
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;
ALTER TABLE datos_2016.seq_data
  OWNER TO postgres;
GRANT ALL ON SEQUENCE datos_2016.seq_data TO public;
GRANT ALL ON SEQUENCE datos_2016.seq_data TO postgres;

2 Answers 2

2

You need to fully qualify the sequence name:

CREATE TABLE datos_2016.data
(
   cdata integer NOT NULL DEFAULT nextval('datos_2016.seq_data'), 
   ....
);
Sign up to request clarification or add additional context in comments.

1 Comment

Great, that was it! I assumed that not having the "public" schema created did not have to specify the schema
0

Try this nextval('datos_2016."seq_data"')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.