Re: Integer Question - Does Limit Value Make Sense

Поиск
Список
Период
Сортировка
От Richard Broersma Jr
Тема Re: Integer Question - Does Limit Value Make Sense
Дата
Msg-id 838715.62981.qm@web31809.mail.mud.yahoo.com
обсуждение исходный текст
Ответ на Integer Question - Does Limit Value Make Sense  (<operationsengineer1@yahoo.com>)
Ответы Re: Integer Question - Does Limit Value Make Sense  (<operationsengineer1@yahoo.com>)
Список pgsql-novice
--- operationsengineer1@yahoo.com wrote:

> hi all,
>
> i'm trying to work my through Agile Webdev with Rails.
>  unfortunately (for me, anyway!), they went with mysql
> as their base db.
>
> i'm trying to work through the code on my own using
> pgsql.
>
> i ran into a problem in their migration script (update
> db script).
>
> they use code as follows:
>
> add_column :products, :price, :decimal, :precision =>
> 8, :scale => 2, :default => 0
>
> you can get the gist of what they are doing with the
> code.
>
> i installed a plugin that let's me use integers to
> handle the money portion, but this didn't work:
>
> add_column :products, :price_in_cents, :integer,
> :limit => 10, :default => 0, :null => false
>
> due the following error:
>
> PGError: ERROR:  syntax error at or near "(" at
> character 48
> : ALTER TABLE products ADD price_in_cents integer(10)
>
> it looks to me like it choked on the format
> "integer(10)" part.
>
> is limit a mysql specific issue for integer?  it was
> suggested on irc, but i think the guy is used to
> mysql.

maybe integer(10) is a mysql extension.  I think that postgresql's numeric datatype will do
whatever you want with 10 digits for dollars and two digits for cents.  You can set it to handle
anything that you want as long as you define the numeric type correctly.

http://www.postgresql.org/docs/8.2/interactive/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL

By the way did you make a finial decision one a table structure for your lending problem?

Regards,

Richard Broersma Jr.

В списке pgsql-novice по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Integer Question - Does Limit Value Make Sense
Следующее
От: "Greg Quinn"
Дата:
Сообщение: Inserting values into a variable table