The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

PostgreSQL and arrays

Last post 06-15-2008, 11:45 AM by pycol. 2 replies.
Sort Posts: Previous Next
  •  06-15-2008, 6:11 AM 9815

    PostgreSQL and arrays

    Is there a way to directly use PostgreSQL array?  Similar to something like:

    Code:
    ArrayTestCollection coll = new ArrayTestCollection();
    coll.LoadAll();
    txtBox.Text = coll[0].ArrayFld[2];


     

    When I try the above I get a "cannot convert from character to string" as though I'm trying to get character 2 not array element 2. 

    Thanks! 

    Phil Mickelson

  •  06-15-2008, 10:33 AM 9817 in reply to 9815

    Re: PostgreSQL and arrays

    EntitySpaces has no built in PostgreSQL array data type handling. The size and dimensions of the array field are not present in the metadata available to us. The "ArrayFld" property just contains a string, as if you viewed the data in PgAdmin, and looked at that column. E.g., a 1-dimensional array with 2 elements would be:

    {meeting,lunch}

    NOTE: Pg arrays are 1-based, and .NET arrays are 0-based.
    If all you need is a query, then you can put Pg specific raw SQL in your Select:

    Code:
    ArrayTestCollection coll = new ArrayTestCollection();
    
    coll.Query.Select(
        "<\"ArrayFld\"[1] AS \"What\">",
        "<\"ArrayFld\"[2] AS \"When\">");
    
    coll.Query.Load();

    If you have a 1-dimensional array, with no commas embedded in any of the array elements, you could try:

    Code:
    ArrayTestCollection coll = new ArrayTestCollection();
    coll.LoadAll();
    
    string[] testArray = coll[0].ArrayFld.Trim('{', '}').Split(',');
    string what = testArray[0];

    But, if it's a multi-dimensional array, or elements can have embedded commas and be wrapped in double-quotes, you'll have to come up with your own parsing routine. In any case, if you need to allow edits and saves, then you will have to concatenate all the elements back into a single, properly constructed string, and store it in "ArrayFld".


    David Neal Parsons
    www.entityspaces.net
  •  06-15-2008, 11:45 AM 9819 in reply to 9817

    Re: PostgreSQL and arrays

    That's what I figured.  But, I thought it was worth the effort to ask.  Thank you again for your fast response!  BTW, a new customer I'm working for has just purchased another license and I suspect I'll have two or three more over the next couple of months.

    Thank you for a great product!
     

View as RSS news feed in XML