PostgreSQL specific datatypes very confusing for beginners who use wrappers around JDBC

From: Merlin Göttlinger <megoettlinger(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: PostgreSQL specific datatypes very confusing for beginners who use wrappers around JDBC
Date: 2014-01-28 20:11:21
Message-ID: CACTajFZ8+hg_kom6QiVBa94Kx9L3XUqZ99RdUsHBFkSb1MoCPQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello fellow postgres users,

I am very new to postgres and databases in general. I needed a database for
a project and I chose to use PostgreSQL. I googled around until I was
confident enough to do the things I wanted to do.

I have written two applications that both use the same database.

The first application was a web application using the
playframework<http://www.playframework.com/>.
It accessed the database using anorm (the default library for database
access from playframework which uses JDBC internally) which was not too
happy about datatypes like macaddr or inet. Because you more or less write
plain SQL-queries with anorm I was able to just cast those types to varchar
when selecting, and from varchar when inserting. But this seemed rather
ugly.

With the second application I decided to try another library for database
access to see if handles those types better. I chose to use
slick<http://slick.typesafe.com/> because
the scala world seems to move towards typesafe <http://typesafe.com/> more
and more. Anyway this library of course also uses JDBC. The new auto
generated code feature suggested I should use String in my code as the type
of the columns with macaddr and inet which I did. When I tried to select
values from the database I was quite happy to see that I got my values
without a complaint about wrong types like with anorm. Then I tried
inserting and was very disappointed to find out that the library tried to
insert the values as varchar and the database refused to accept my inserts
because they had the wrong type.

With the help of Craig Ringer
<http://stackoverflow.com/q/21285414/1876344>I was able to resolve
this problem by implementing implicit casts from
varchar to macadr and inet but this seems rather unintuitive. I don't know
if this is just a beginner problem but at least in my opinion it is rather
complicated to use the postgres specific types and features from JDBC and
its wrappers.

For example if the database would check if the varchar I try to insert into
the column with type macaddr is actually a valid MAC address and then take
it as macaddr this would have made my life a lot easier and safed me from
hours of googeling and trying around. I don't know what problems this would
introduce but I would love to see this made a bit simpler to provide a
simpler start for PostgreSQL newcomers like me.

Anyway keep the good work up.

Sincearely,

Merlin Göttlinger

PS: English is not my native language so please excuse spelling or grammar
errors.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2014-01-28 20:35:34 Re: Composite type
Previous Message Susan Cassidy 2014-01-28 20:06:33 Re: problem with grant all privileges