Array for Insertion - Mailing list pgsql-novice

From Bee.Lists
Subject Array for Insertion
Date
Msg-id 24DDEB78-BD41-4E38-BE4E-492EF1961327@gmail.com
Whole thread Raw
List pgsql-novice
Can anybody shed some light on this?

I have an array in Ruby, which I need to use inside various statements in PostgreSQL.

a = [“Alex”, “Bert”, “Charlie”]

Formatting that for insertion is oddly not represented in any methods or functionality anywhere.

-> PostgreSQL is on its own, so it doesn’t have to respect Ruby by any means.  However PostgreSQL doesn’t even have a
functionto format any of its own arrays into friendly string format: 

(‘Alex’, ‘Bert’, ‘Charlie’)

a.join(‘,‘)             # => Alex’,‘Bert’,‘Charlie

…which is not usable.  Yes I know this isn’t a PostgreSQL function. Getting to a PostgreSQL array type is the first
challenge,then using array_to_string(a, ‘,’) still results in this issue. 

-> PG Gem formats arrays to PostgreSQL arrays:

puts PG::TextEncoder::Array.new.encode(a)    # => {Alex,Bert,Charlie}

…which brings us back to the PostgreSQL challenge above.

-> Ruby, from my experience, can’t take an array and wrap its elements in a fully encapsulating join, such as this
suggestion:

a = [“Alex”, “Bert”, “Charlie”]
puts a.fulljoin(“‘“, “, "        # => ‘Alex’, ‘Bert’, ‘Charlie’


Yes, indeed, I can write my own, and extend the array Class.  However I find that in the language, a useful go-to gem
withloads of PostgreSQL functions, and the database itself, all are void of any functionality in this space.   

Jumping from language type formats to database formats should be second nature, so I’m confused as to why.

I guess this is more of a theoretical question, unless I’m completely blind to some methods.  Any insight out there?



Cheers, Bee






pgsql-novice by date:

Previous
From: Stephen Frost
Date:
Subject: Re: WAL on zfs Settings
Next
From: Peter Neave
Date:
Subject: Exclusive Locks on Insert into large Logging tables