Re: Empty to NULL conversion - Ruby - Postgres ?

From: Steve Atkins <steve(at)blighty(dot)com>
To: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Empty to NULL conversion - Ruby - Postgres ?
Date: 2008-02-02 01:48:19
Message-ID: C0E5AFC8-1B40-44E7-B968-57CBF814F518@blighty.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Feb 1, 2008, at 5:33 PM, Venks wrote:

> Hi,
>
> I am trying to copy some data from MySQL to Postgres using Ruby. This
> is NOT a MySQL to PostgreSQL conversion project. I need to read the
> data from a MySQL database and load it into PostgreSQL database.
>
> How do I handle "nil" in ruby and convert them into NULL so that I can
> insert NULL into INT columns instead of empty values? In short I am
> getting the following popular error:
>
> invalid input syntax for integer: "" (PGError)
>
> This is because when I read data from MySQL, all the NULL values are
> converted into "nil" in Ruby and inserting them into Postgres is an
> issue because "nil" is being transmitted as "" (empty) and not as SQL
> NULL.

That all sounds perfectly reasonable up until the "nil" being translated
to the empty string. It sounds like the issue is the ruby module you're
using to talk to postgresql, or your use of it.

The docs for Ruby DBI suggest that nil is converted into SQL null
correctly, so you're going to have to be more specific about what
you're doing and what problem you're seeing, I think.

Cheers,
Steve

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Kempter 2008-02-02 03:06:15 temp table question
Previous Message Venks 2008-02-02 01:33:41 Empty to NULL conversion - Ruby - Postgres ?