PostgreSQL(创建表)

发布于 2025-02-08 04:45:42 字数 683 浏览 5 评论 0原文

我正在尝试创建一个表。其中一列; “ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神回复 2025-02-15 04:45:42

是的,数字数据类型允许负值。

yes ,numeric data type allows negative values .

莳間冲淡了誓言ζ 2025-02-15 04:45:42

坐标的正确数据类型将为double Pecision

更正确的数据类型代表start_latstart_lng将是point

但是,如果您想在数据库内使用这些坐标,可以做的最好的事情是安装gis扩展名并将其建模为几何地理

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文