1

Hi I am new to postgres, while inserting the data into a money type field I am getting the error as.. Here my sample table is as

CREATE TABLE x_table
(
  t_name character varying(40) NOT NULL,
  currency money
)

INSERT INTO x_table(t_name, currency)
VALUES ('TEST', 1000);

and getting the error message as ERROR: column "currency" is of type money but expression is of type integer SQL state: 42804.

So can any one say how to resolve this.. Thanks in advance

rageit
  • 3,513
  • 1
  • 26
  • 38
RamBen
  • 990
  • 1
  • 9
  • 17

1 Answers1

5

In modern versions (tested with 9.1 and 9.3) the above code example works as is.

In older versions there was no implicit cast defined from integer to money.
Quoting the the release notes for Postgres 9.1:

Add support for casting from int4 and int8 to money (Joey Adams)

Also, be sure to consider alternatives to store currency information:
PostgreSQL: Which Datatype should be used for Currency?

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • Thanks Erwin,Worked with 9.1 and may I know to use that money to int casting while inserting from the command prompt... if we are using in the older versions – RamBen Jun 03 '14 at 04:31