I am trying to create a table. One of the columns; "start_lng" meaning start longitude, includes a negative decimal number (-87.223655662). As I create my columns what kind of data type would this categorize as. I was going to use INT
but then I realized that can only include whole numbers. Then I thought about NUMERIC
but I am confused on whether or not that can be negative or not. I have attached my code below. Please help.
CREATE TABLE may_2021 (
ride_id INTEGER NOT NULL,
rideable_type VARCHAR(50) NOT NULL,
started_at TIMESTAMP NOT NULL,
ended_at TIMESTAMP NOT NULL,
ride_length INTERVAL(1000) NOT NULL,
day_of_week INTEGER NOT NULL,
start_station_name TEXT,
start_station_id VARCHAR(75),
end_station_name TEXT,
end_station_id VARCHAR(75),
start_lat NUMERIC(15,15) NOT NULL,
start_lng NUMERIC(15,15) NOT NULL,
end_lat NUMERIC(15,15) NOT NULL,
end_lng NUMERIC(15,15) NOT NULL,
member_casual TEXT
)
CodePudding user response:
The correct data type for coordinates would be double precision
.
The even more correct data type to represent start_lat
and start_lng
would be point
.
But the best thing you can do if you want to use these coordinates inside the database would be to install the PostGIS extension and model it as a geometry
or geography
.
CodePudding user response:
yes ,numeric data type allows negative values .