Gen_random_uuid() (from pgcrypto) is assumed if no :default option was passed to create_table. A point is casted to an array containing x and y coordinates. # => "32:01:16:6d:05:ef" 1.11 Geometric TypesĪll geometric types, with the exception of points are mapped to normal text. The macaddr type is mapped to normal text. The types inet and cidr are mapped to Ruby IPAddr objects. You can use uuid type to define references in migrations: # db/migrate/20150418012400_create_blog.rbĮnable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')Ĭreate_table :posts, id: :uuid, default: 'gen_random_uuid()'Ĭreate_table :comments, id: :uuid, default: 'gen_random_uuid()' do |t| You need to enable the pgcrypto (only PostgreSQL >= 9.4) or uuid-ossp extension to use uuid. ADD VALUE cannot be executed inside of a transaction block so here we are using disable_ddl_transaction!ĪLTER TYPE article_status ADD VALUE IF NOT EXISTS 'archived' AFTER 'published' ![]() To add a new value before/after existing one you should use ALTER TYPE: # db/migrate/20150720144913_add_new_state_to_articles.rb They are mapped as normal text columns: # db/migrate/20131220144913_create_articles.rb ) # db/migrate/20140207133952_create_contacts.rbĬurrently there is no special support for enumerated types. ![]() ![]() They are mapped to normal text columns: CREATE TYPE full_address AS Select("upper(duration) AS ends_at").firstĮvent.ends_at # => Thu, 1.6 Composite TypesĬurrently there is no special support for composite types. This type is mapped to Ruby Range objects. # The -> operator returns the original JSON type (which might be an object), whereas -> returns textĮvent.where("payload->'kind' = ?", "user_renamed") 1.5 Range Types You need to enable the hstore extension to use hstore. Following is a list of types, that are supported by the PostgreSQL adapter. PostgreSQL offers a number of specific datatypes. It describes how to properly setup Active Record for PostgreSQL. To get started with PostgreSQL have a look at the configuring Rails guide. In order to use the PostgreSQL adapter you need to have at least version 9.3 installed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |