PostgreSQL(创建表)
我正在尝试创建一个表。其中一列; “ start_lng”的意思是开始经度,包括一个负小数号(-87.223655662)。当我创建列时,将哪种数据类型归类为。我要使用int
,但是后来我意识到只能包括整数。然后,我考虑了数字
,但我对这是否可能为负面感到困惑。我在下面附上了我的代码。请帮忙。
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
)
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
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,数字数据类型允许负值。
yes ,numeric data type allows negative values .
坐标的正确数据类型将为
double Pecision
。更正确的数据类型代表
start_lat
和start_lng
将是point
。但是,如果您想在数据库内使用这些坐标,可以做的最好的事情是安装gis扩展名并将其建模为
几何
或地理
。The correct data type for coordinates would be
double precision
.The even more correct data type to represent
start_lat
andstart_lng
would bepoint
.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
orgeography
.