[odb-users] Use of postgresql array mapping for native views

Lisa Fiedler lfiedler at informatik.uni-leipzig.de
Tue Apr 23 03:05:40 EDT 2019


On 4/22/19 6:02 PM, Boris Kolpackov wrote:
> Lisa Fiedler <lfiedler at informatik.uni-leipzig.de> writes:
>
>> value_traits<std::vector<u_int64_t>, id_string>
>>
>> [...]
>>
>> typedef std::vector<u_int64_t> id_vector;
>> #pragma db value(id_vector) type("BIGINT[]")
> This doesn't make much sense to me: you are providing a mapping
> traits for vector<u_int64_t> to string but then trying to use
> BIGINT[] as the database type?

I agree. I am sorry.

But even after writing the following lines (note I am using vector<int> 
now to reproduce the instructions in the article):

#pragma db map type("BIGINT *\\[(\\d*)\\]") \
                as("TEXT")                    \
                to("(?)::BIGINT[$1]")        \
                from("(?)::TEXT")

typedef std::vector<int> id_vector;
#pragma db value(id_vector) type("BIGINT[]")

and then using precisely the same value_traits as in

https://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/

and then trying to do

#pragma db view
struct queryTaxonomyPath_view{

     #pragma db type("BIGINT[]")
     id_vector path;
};

and

     odb::result<queryTaxonomyPath_view> res
             (db_->query<queryTaxonomyPath_view>("SELECT * FROM 
complete.generate_taxonomic_path(" +to_string(taxId) + "::bigint)"));
     cout << "size: " << res.size() << endl;

     for(auto & it : res){
         cout << it.path.size() << endl;

     }

does compile, however never terminates upon execution. res.size() is 
still printed, but at the for loop the program gets stuck.

generate_taxonomic_path is a postgresql user defined function, which 
returns a table with an attribute of type BIGINT[].

I don't understand why this does not work out ?

>
> I suggest that you read through this article and see if it
> clarifies things:
>
> https://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/



More information about the odb-users mailing list