Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
PG array returned as String
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
François Beausoleil  
View profile  
 More options Nov 4 2012, 8:35 am
From: François Beausoleil <francois.beausol...@gmail.com>
Date: Sun, 4 Nov 2012 08:35:02 -0500
Local: Sun, Nov 4 2012 8:35 am
Subject: PG array returned as String

Hi!

I'm trying to use the PGArray extension, but the Ruby arrays are returned as strings, instead of Array instances. I'm using versions:

$ bundle show | grep -E "sequel|pg"
  * pg (0.14.1)
  * sequel (3.41.0)
  * sequel_pg (1.6.1)

My setup code is (within a Padrino app):

Sequel::Model.plugin(:schema)
Sequel::Model.raise_on_save_failure = false # Do not throw exceptions on failure
Sequel::Model.db = Sequel.connect((ENV["PORTAL_DATABASE_URL"] || "postgres://localhost/portal_#{Padrino.env}").sub("jdbc:postgresql", "postgres"), :loggers => [Padrino.logger])

require "sequel/extensions/pg_array"
Sequel::Model.db.extend Sequel::Postgres::PGArray::DatabaseMethods

Then I ask for active users with their permissions and associated accounts:

user0 = User.naked.
  select(:users__email, :users__name, :users__default_ui_language, :users__id, :users__user_id, :array_agg.sql_function(:domain).as(:domains), :array_agg.sql_function(:permission).as(:products)).
  inner_join(:user_accounts, [:email]).
  inner_join(:account_product_permissions, [:domain]).
  filter(users__id: authenticated_user_id, users__user_state: "active").
  group(:users__email, :users__name, :users__default_ui_language, :users__id, :users__user_id).
  first

user1 = User.
  select(:users__email, :users__name, :users__default_ui_language, :users__id, :users__user_id, :array_agg.sql_function(:domain).as(:domains), :array_agg.sql_function(:permission).as(:products)).
  inner_join(:user_accounts, [:email]).
  inner_join(:account_product_permissions, [:domain]).
  filter(users__id: authenticated_user_id, users__user_state: "active").
  group(:users__email, :users__name, :users__default_ui_language, :users__id, :users__user_id).
  first

I'm running the query twice to see if there are differences with the #naked call, while debugging. The generated query is (identical between both cases, as expected):

SELECT
    "users"."email"
  , "users"."name"
  , "users"."default_ui_language"
  , "users"."id", "users"."user_id"
  , array_agg("domain") AS "domains"
  , array_agg("permission") AS "products"
FROM "users"
  INNER JOIN "user_accounts" USING ("email")
  INNER JOIN "account_product_permissions" USING ("domain")
WHERE (("users"."id" = 2) AND ("users"."user_state" = 'active'))
GROUP BY "users"."email", "users"."name", "users"."default_ui_language", "users"."id", "users"."user_id"
LIMIT 1

which is, as far as I'm concerned, exactly what I want. Running the above query in psql returns correct values in domains and products, namely text::[] values.  Unfortunately, the resulting hash has unparsed values:

(rdb:1) pp user0
{:email=>"y...@customer.com",
 :name=>"Customer",
 :default_ui_language=>"fr",
 :id=>2,
 :user_id=>"aee3a8ff-6961-4700-87e5-d5eb0546c0ac",
 :domains=>"{yourdomain,yourdomain}",
 :products=>"{dashboard,\"weekly report\"}"}

(rdb:1) pp user1
#<User @values={:email=>"y...@customer.com", :name=>"Customer", :default_ui_language=>"fr", :id=>2, :user_id=>"aee3a8ff-6961-4700-87e5-d5eb0546c0ac", :domains=>"{yourdomain,yourdomain}", :products=>"{dashboard,\"weekly report\"}"}>

I expected user0.fetch(:products) to return the Ruby value ["dashboard", "weekly report"].

Did I forget to load an extension? According to 3.34's[1] release notes, I only need to load the PGArray extension.

Thanks!
François

  [1]: http://sequel.rubyforge.org/rdoc/files/doc/release_notes/3_34_0_txt.html


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
François Beausoleil  
View profile  
 More options Nov 4 2012, 9:01 am
From: François Beausoleil <francois.beausol...@gmail.com>
Date: Sun, 4 Nov 2012 06:01:23 -0800 (PST)
Local: Sun, Nov 4 2012 9:01 am
Subject: Re: PG array returned as String

Well, I managed to fix my problem. I had to load the extension like this:

Sequel::Model.db.extension :pg_array

I found the proper way to load the extension in the source code at
lib/sequel/extensions/pg_array.rb.

I did NOT find this documentation
on http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Postgres/PGAr...
or in the 3.35 release notes. Now that I've read the source, I see the
documentation is indeed extensive, but I didn't find the link to the
extensions' documentation from the main documentation site. Where should I
have looked?

Thanks!
François


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Nov 4 2012, 11:50 am
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Sun, 4 Nov 2012 08:50:44 -0800 (PST)
Local: Sun, Nov 4 2012 11:50 am
Subject: Re: PG array returned as String

On Sunday, November 4, 2012 6:01:23 AM UTC-8, François Beausoleil wrote:
> Well, I managed to fix my problem. I had to load the extension like this:

> Sequel::Model.db.extension :pg_array

> I found the proper way to load the extension in the source code at
> lib/sequel/extensions/pg_array.rb.

> I did NOT find this documentation on
> http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Postgres/PGAr... in the 3.35 release notes. Now that I've read the source, I see the
> documentation is indeed extensive, but I didn't find the link to the
> extensions' documentation from the main documentation site. Where should I
> have looked?

For documentation on plugins/extensions, you should go
to http://sequel.rubyforge.org/plugins.html and click on the appropriate
plugin/extension.  For pg_array, that would
be http://sequel.rubyforge.org/rdoc-plugins/files/lib/sequel/extensions/...,
which does explain how to load the extension.  Extension documentation is
done at the file level and not the class level, as extensions are not tied
to a particular class.

Thanks,
Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
François Beausoleil  
View profile  
 More options Nov 5 2012, 11:46 am
From: François Beausoleil <francois.beausol...@gmail.com>
Date: Mon, 5 Nov 2012 11:46:10 -0500
Local: Mon, Nov 5 2012 11:46 am
Subject: Re: PG array returned as String

Le 2012-11-04 à 11:50, Jeremy Evans a écrit :

> For documentation on plugins/extensions, you should go to http://sequel.rubyforge.org/plugins.html and click on the appropriate plugin/extension.  For pg_array, that would be http://sequel.rubyforge.org/rdoc-plugins/files/lib/sequel/extensions/..., which does explain how to load the extension.  Extension documentation is done at the file level and not the class level, as extensions are not tied to a particular class.

Ha, I see. I was hitting http://sequel.rubyforge.org/ then following the documentation link. There's an Extensions/Plugins link that I followed, and that brought me to the RDoc for the plugins.

Thanks for your time!
François


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »