Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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. 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 because the scala world seems to move towards typesafe 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 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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux