Giter VIP home page Giter VIP logo

Comments (3)

ged avatar ged commented on August 22, 2024

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


No, the driver doesn't presume to know how to convert anything for you -- that's left to higher-level abstractions like Sequel, ActiveRecord, etc. The library returns pretty much exactly what the libpq library returns, with the notable exception of associating the Encoding (where possible) under Ruby 1.9.

However, there are two methods on the PGconn object to help you with doing the conversion yourself: [[http://deveiate.org/code/pg/PGconn.html#escape_bytea-instance_method|PGconn#escape_bytea]] and [[http://deveiate.org/code/pg/PGconn.html#unescape_bytea-instance_method|PGconn#unescape_bytea]].

There's more details about the design of the client library, including the topic of data type conversion, on [[http://wiki.postgresql.org/wiki/Driver_development|the PostreSQL wiki]].

Does that answer your questions?

from ruby-pg.

ged avatar ged commented on August 22, 2024

Original comment by Don Park (Bitbucket: donpdonp, GitHub: donpdonp).


The first guideline in the wiki is "Avoid Magic" or the principle of the least surprise. I believe that if I have a ruby string and store it with pg, the retrieved string should be identical. Do you agree?

if so, thats not happening. A rails app is storing an authentication string and getting a different string back so the app is breaking when postgres is using the 'new' binary escape mode (introduced in version 9), but works fine when the postgres 9 daemon is using the old escape mode.

from ruby-pg.

ged avatar ged commented on August 22, 2024

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


My point was that the pg' library returns only what libpq' returns without modifications other than associating the encoding. This, to me, is avoiding "magic". The driver returns exactly what the client library returns from the database, without assuming that you'd want it converted to something else.

As with many cases when people cite the Principle of Least Surprise, it's dependent on whose surprise you're trying to avoid. In this case, I prefer not to surprise people who have come to expect that `pg' will behave identically to libpq, and who have possibly built libraries around these behaviors. It's the job of higher-level abstractions to convert the notion of a "binary string" into whatever Ruby construct corresponds to its representation by PostgreSQL.

I apologize if this makes what you're trying to do difficult. As I mentioned above, there are methods to help with escaping and unescaping bytea column values, but I'm unwilling to introduce magical conversions of any column values from a PGresult.

from ruby-pg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.