PostgreSQL – How to Create Tables with Geometry

postgispostgresql

I need to create 2 tables with distinct geometry.

One needs to be a table that has point information. The other needs to be a table that has line information.

They do not need to be populated as this is just a test. They just need to have the geometry column.

The code so far is:

CREATE TABLE point

CREATE TABLE line

How to add the geometry into the code?

Best Answer

The simple answer is:

create table points ( p POINT not null); 
create table lines ( l LINE not null);

Then inserts look like this:

insert into points (p) values (POINT(1.2, 123.1));
insert into lines (l) values (LINE(POINT(1.2, 123.1), POINT(-5, -123)));

You probably want to build indexes if you want to have some lookups on them. Also a primary key may be beneficial.