1

I've seen the gid field/column in a lot of PostGIS tables and questions. It seems to be a unique ID often available (see e.g. In PostGIS is it possible to create a View with a unique ID?)

My questions are:

Is the gid field guaranteed to exist in all PostGIS tables?

If not guaranteed at all times, when are they guaranteed to exist and when are they not?

For example, tt seems to me that tables imported using shp2pgsql all have the gid field. But I wanted to know if I can rely on the existence of such a unique id field, which I'd like to use as a primary key.

(I'm using PostgreSQL 9.5+, PostGIS 2.2+)

2

Not if you create the table yourself. If you don't specify a primary key field in Postgresql, you won't have one.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.