0

I have a databse dump db.sql.schema I import it using psql -U user dbname < ~/db.sql.schema After import in my DB I see table mytable but not mytable_id_seq.

# \d mytable
 Table mytable
 Column | Type | Collation | Nullable | Default 
-------------------+--------------+-----------+----------+---------
 id | integer | | not null | 
 field1 | integer | | not null | 
 field2 | integer | | not null | 
 field3 | integer | | not null | 

I got the follwong error:

# INSERT INTO mytable (field1, field2, field3) VALUES (1, 1, 1) RETURNING mytable.id;
ERROR: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, 1, 1, 1).

My postgres version is 10.12 It looks like auto-increment of id doesn't works. Is it a postgres issue or issue with my dump? Is it loo old or too new?

asked Mar 19, 2020 at 13:23
1
  • I got an error because of CREATE SEQUENCE qqq AS smallint; ERROR: syntax error at or near "AS" LINE 1: CREATE SEQUENCE qqq AS smallint; But my postgres10.12 should support AS data_type! Commented Mar 19, 2020 at 14:03

1 Answer 1

2

You are trying to import a dump from a recent PostgreSQL version into an older PostgreSQL server. That is not supported.

Your only option is to manually edit the dump and fix any syntax that the older server doesn't understand.

Check for the first error message you get when restoring the dump, later ones can be consequences of the first one.

answered Mar 19, 2020 at 20:46
1
  • Yes, you are right. I previously I checked the postgres version by psql -V but in my case psql was 10.12, but postgres itself was 9.5! Commented Mar 20, 2020 at 12:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.