【问题标题】:How to create a geography and double precision database columns in Rails如何在 Rails 中创建地理和双精度数据库列
【发布时间】:2021-01-10 11:11:32
【问题描述】:

我想用这个 postgresql 查询创建一个表。如何使用 DOUBLE PRECISION 和 Geography 列进行 rails 迁移?

CREATE TABLE poi_trace (
    poi_id BIGINT REFERENCES pois(id),
    trace_id BIGINT REFERENCES traces(id),
    geog GEOGRAPHY(Point, 4326),
    advance_on_trace DOUBLE PRECISION,
    active BOOLEAN
);

【问题讨论】:

    标签: ruby-on-rails postgresql migration


    【解决方案1】:

    您可以在迁移中运行自定义 sql

    class ExampleMigration < ActiveRecord::Migration
      def up
        execute <<-SQL
          CREATE TABLE poi_trace (
            poi_id BIGINT REFERENCES pois(id),
            trace_id BIGINT REFERENCES traces(id),
            geog GEOGRAPHY(Point, 4326),
            advance_on_trace DOUBLE PRECISION,
            active BOOLEAN
          );
        SQL
      end
     
      def down
        drop_table :poi_trace
      end
    end
    

    Read more about this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-13
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      • 2023-03-19
      • 2014-10-22
      相关资源
      最近更新 更多