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

Поиск
Список
Период
Сортировка
От Merlin Göttlinger
Тема PostgreSQL specific datatypes very confusing for beginners who use wrappers around JDBC
Дата
Msg-id CACTajFZ8+hg_kom6QiVBa94Kx9L3XUqZ99RdUsHBFkSb1MoCPQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: PostgreSQL specific datatypes very confusing for beginners who use wrappers around JDBC
Список 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. 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.

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

Предыдущее
От: Kevin Grittner
Дата:
Сообщение: Re: Composite type
Следующее
От: John R Pierce
Дата:
Сообщение: Re: PostgreSQL specific datatypes very confusing for beginners who use wrappers around JDBC