PostgreSQL array data type

Request new PGNP funclionality and enhancements.

PostgreSQL array data type

Postby pgdude » Sun Apr 12, 2009 12:04 pm

What is the official status on arrays. How are they going to be implemented?
Code sample would help I guess. Just curios If it is worth waiting for version 1.3.
pgdude
 
Posts: 5
Joined: Sun Apr 12, 2009 11:49 am

Re: PostgreSQL array data type

Postby Moderator » Mon Apr 13, 2009 12:27 am

We have finished implementation of the multi-dimensional arrays in the Provider, version 1.3.

Since OLEDB does not support arrays, we have implemented them as VARIANT wrappers around SAFEARRAYs. We decided that an array lower index will be 1 (not 0).

The array elements accessed differently depending on the programming language. For example, let's PostgreSQL array declared as:
Code: Select all
CREATE TABLE test_arrays
(
  "array2D" smallint[][],
  ...
)

// Populate "array2D" as 5x7 matrix
INSERT INTO test_arrays("array2D",...)
VALUES('{{3,16,9,22,15,0,100},{20,8,21,14,2,0,100},{7,25,13,1,19,0,100},{24,12,5,18,6,0,100},{11,4,17,10,23,0,100}}',...)


The following C# sample demonstrates access to the 2D array:
Code: Select all
string sConnectionStr = "Provider=PGNP.1;...";
OleDbConnection conn = new OleDbConnection(sConnectionStr);
conn.Open();

OleDbCommand dbcmd = new OleDbCommand("SELECT \"array2D\" FROM test_arrays", conn);
OleDbDataReader dr = dbcmd.ExecuteReader();

while (dr.Read())
{
    object o = dr.GetValue(0);
    if (o is DBNull)
        Console.WriteLine("[NULL]");
    else
    {
        Array array = o as Array;
        switch (lang_req.Rank)
        {
        case 1:
              for (int i = lang_req.GetLowerBound(0); i < lang_req.GetLowerBound(0) + lang_req.GetLength(0); i++)
              {
                   object x = lang_req.GetValue(i);
                   Console.WriteLine(String.Format("{0}>{1}", i, x));
              }
              break;

        case 2:
            for (int j = lang_req.GetLowerBound(1); j < lang_req.GetLowerBound(1) + lang_req.GetLength(1); j++)
            {
                for (int i = lang_req.GetLowerBound(0); i < lang_req.GetLowerBound(0) + lang_req.GetLength(0); i++)
                {
                   object x = lang_req.GetValue(i, j);
                   Console.WriteLine(String.Format("({0},{1}) > {2}", i, j, x));
                }
            }
            break;

        case 3:
            for (int k = lang_req.GetLowerBound(2); k < lang_req.GetLowerBound(2) + lang_req.GetLength(2); k++)
            {
                 for (int j = lang_req.GetLowerBound(1); j < lang_req.GetLowerBound(1) + lang_req.GetLength(1); j++)
                 {
                     for (int i = lang_req.GetLowerBound(0); i < lang_req.GetLowerBound(0) + lang_req.GetLength(0); i++)
                     {
                         object x = lang_req.GetValue(i, j, k);
                         Console.WriteLine(String.Format("({0},{1},{2}) > {3}", i, j, k, x));
                     }
                 }
             }
             break;
        }
    }
}


If you compile and execute the C# sample you will notice that indexes are:
Code: Select all
(1,1) > 3
(2,1) > 16
(3,1) > 9
(4,1) > 22
(5,1) > 15
(6,1) > 0
(7,1) > 100
(1,2) > 20
(2,2) > 8
(3,2) > 21
(4,2) > 14
(5,2) > 2
(6,2) > 0
(7,2) > 100
(1,3) > 7
(2,3) > 25
(3,3) > 13
(4,3) > 1
(5,3) > 19
(6,3) > 0
(7,3) > 100
(1,4) > 24
(2,4) > 12
(3,4) > 5
(4,4) > 18
(5,4) > 6
(6,4) > 0
(7,4) > 100
(1,5) > 11
(2,5) > 4
(3,5) > 17
(4,5) > 10
(5,5) > 23
(6,5) > 0
(7,5) > 100


That corresponds to C# array:
Code: Select all
short array2D[7,5];      // it can be confusing because PostgreSQL array is 5x7!


However, C++ allows to access the array elements similarly to PostgreSQL declaration.
User avatar
Moderator
Site Admin
 
Posts: 302
Joined: Wed Oct 29, 2008 11:27 pm

Re: PostgreSQL array data type

Postby pgdude » Wed Apr 15, 2009 9:44 am

Thank you for the C# sample. Would you have a C++ code handy?
pgdude
 
Posts: 5
Joined: Sun Apr 12, 2009 11:49 am

Re: PostgreSQL array data type

Postby Moderator » Fri Apr 17, 2009 12:02 am

C++ sample demonstrating multidimentional arrays access via PGNP provider

Code: Select all
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
using namespace std;

#import "msado15.dll" no_namespace rename("EOF", "adoEOF")

void MyArrayPrint(const _variant_t& v);

int _tmain(int argc, _TCHAR* argv[])
{
   CoInitialize (NULL);

   _ConnectionPtr pConn;

   try   
   {
      HRESULT hr = pConn.CreateInstance (__uuidof (Connection));
      if (FAILED (hr))
      {
         cout << "Can't create Connection instance" << endl;
         return 1;
      }
      hr = pConn->Open (_bstr_t ("Provider=PGNP.1;Password=12345;User ID=postgres;Initial Catalog=postgres;Data Source=localhost;Extended Properties=\"\""), _bstr_t (""), _bstr_t (""), adModeUnknown);
      if (FAILED(hr))
      {
         cout << "Can't open datasource" << endl;
         return 2;
      }

      _CommandPtr pCommand;

      hr = pCommand.CreateInstance (__uuidof (Command));
      if (FAILED (hr))
      {
         cout << "Can't create an instance of Command" << endl;
         return 3;
      }

      pCommand->ActiveConnection = pConn;
      pCommand->CommandText = "select \"array2D\"from test_arrays";


      _RecordsetPtr pRecordset;

      hr = pRecordset.CreateInstance (__uuidof (Recordset));
      if (FAILED (hr))
      {
         cout << "Can't create an instance of Recordset" << endl;
         return 4;
      }

      pRecordset->CursorLocation = adUseClient;
      pRecordset->Open ((IDispatch *) pCommand, vtMissing, adOpenForwardOnly, adLockUnspecified, adCmdUnknown);

      if (!pRecordset->GetadoEOF ())
      {
         _variant_t v = pRecordset->Fields->GetItem("array2D")->GetValue();

         MyArrayPrint(v);
      }

      pRecordset->Close ();
   }
   catch ( _com_error &e )
   {
      cout << e.Description() << endl;
   }
   catch (...)
   {
      cout << "*** Unhandled Exception ***" << endl;
   }

   if ((pConn->State & adStateOpen) == adStateOpen)
      pConn->Close();

   CoUninitialize();

   return 0;
}

void PrintArrayElement(VARTYPE vt, LPVOID pvData, LONG i)
{
   switch (vt)
   {
   default: cout << "?unknown vartype"; break;

   case VT_I2: case VT_UI2:   cout << ((short*)pvData)[i]; break;

   case VT_I4: case VT_UI4:   cout << ((int*)pvData)[i]; break;

   case VT_BSTR: { _bstr_t bstrTemp(((BSTR*)pvData)[i], true); cout << LPCSTR(bstrTemp); } break;
   }
}

void MyArrayPrint(const _variant_t& v)
{
   if (0 == (v.vt & VT_ARRAY))
   {
      cout << "Not array, vt=" << v.vt;
      return;
   }

   VARTYPE vt = v.vt & ~VT_ARRAY;   // element type

   switch (v.parray->cDims)
   {
      case 1:
         for (LONG i = v.parray->rgsabound[0].lLbound; i < v.parray->rgsabound[0].lLbound + v.parray->rgsabound[0].cElements; i++)
         {
            cout << i << ">";
            PrintArrayElement(vt, v.parray->pvData, i-v.parray->rgsabound[0].lLbound);   // the implementation requires zero-based indexes
            cout << endl;
         }
         break;

      case 2:
         for (LONG i = v.parray->rgsabound[0].lLbound; i < v.parray->rgsabound[0].lLbound + v.parray->rgsabound[0].cElements; i++)
         {
            for (LONG j = v.parray->rgsabound[1].lLbound; j < v.parray->rgsabound[1].lLbound + v.parray->rgsabound[1].cElements; j++)
            {
               cout << "(" << i << "," << j << ")>";
               PrintArrayElement(vt, v.parray->pvData,
                  (i-v.parray->rgsabound[0].lLbound) * v.parray->rgsabound[1].cElements +
                  (j-v.parray->rgsabound[1].lLbound));   // the implementation requires zero-based indexes
               cout << endl;
            }
         }
         break;

      case 3:
         for (LONG i = v.parray->rgsabound[0].lLbound; i < v.parray->rgsabound[0].lLbound + v.parray->rgsabound[0].cElements; i++)
         {
            for (LONG j = v.parray->rgsabound[1].lLbound; j < v.parray->rgsabound[1].lLbound + v.parray->rgsabound[1].cElements; j++)
            {
               for (LONG k = v.parray->rgsabound[2].lLbound; k < v.parray->rgsabound[2].lLbound + v.parray->rgsabound[2].cElements; k++)
               {
                  cout << "(" << i << "," << j << "," << k << ")>";
                  PrintArrayElement(vt, v.parray->pvData,
                     ((i-v.parray->rgsabound[0].lLbound) * v.parray->rgsabound[1].cElements +
                      (j-v.parray->rgsabound[1].lLbound)) * v.parray->rgsabound[2].cElements +
                     (k-v.parray->rgsabound[2].lLbound));   // the implementation requires zero-based indexes
                  cout << endl;
               }
            }
         }
         break;
   }
}
User avatar
Moderator
Site Admin
 
Posts: 302
Joined: Wed Oct 29, 2008 11:27 pm

bogc fnzjveklfnuz

Postby hxdrbunctsyw » Mon Sep 22, 2014 9:54 pm

http://smokymountainportraits.com/plugins/Pzj/wXPC http://www.cse-mari.ru/backup/Ttk/1loMg http://www.cse-mari.ru/backup/7d4c/sK9 http://smokymountainportraits.com/plugins/jfXC/TpE http://www.reconstyle.nl/libraries/E5wu/Kj6fQ http://www.cse-mari.ru/backup/51VMu http://www.cse-mari.ru/backup/Ttk/0hRV http://terastud.ro/plugins/dilX/SGIx http://luxusshop.hu/libraries/emRe/Xea http://www.tfxconnect.com/stats/7ztr/Lvb http://www.cse-mari.ru/backup/ http://luxusshop.hu/libraries/VdO/sClfd http://www.brothertrouble.com/components/msBV/EiHF http://luxusshop.hu/libraries/VdO/ http://www.jerseyslivinglegend.co.je/plugins/PdO3/FbCpL http://www.tfxconnect.com/stats/yN5Pz/szg19 http://terastud.ro/plugins/qqjk/DNHIm http://www.planetzog.co.za/components/oQP7v/Index.php http://terastud.ro/plugins/qqjk/81f http://www.jerseyslivinglegend.co.je/plugins/u1h/DZ1N http://www.reconstyle.nl/libraries/E5wu/ http://www.estetska.com/pdf/EmQW/p5ehd http://www.reconstyle.nl/libraries/igF/6nL http://www.tfxconnect.com/stats/4MSn/VnKb http://www.planetzog.co.za/components/BOEo/Index.phph3Erc http://www.3alarmseries.com/documents/F52G/EEYv http://www.tfxconnect.com/stats/2N8/ http://www.brothertrouble.com/components/qEtD/lD9n http://luxusshop.hu/libraries/jwqRR http://luxusshop.hu/libraries/nZf/ http://www.tfxconnect.com/stats/7ztr/YX3n http://smokymountainportraits.com/plugins/tLH/Rc3 http://www.estetska.com/pdf/EmQW/mZHoM http://www.brothertrouble.com/components/W4da0/GWp http://terastud.ro/plugins/CQav/ http://www.estetska.com/pdf/n0Z/4kw2 http://terastud.ro/plugins/CQav/h6bz8 http://www.reconstyle.nl/libraries/sUeTs/E7j http://smokymountainportraits.com/plugins/hIg8/ http://luxusshop.hu/libraries/emRe/jru2W http://luxusshop.hu/libraries/lz8/70rYI http://www.brothertrouble.com/components/a79uz/mMqfX http://www.3alarmseries.com/documents/0zh/pJVNM http://www.jerseyslivinglegend.co.je/plugins/8KM/x5cCK http://www.cse-mari.ru/backup/51VMu/rTjV http://www.cse-mari.ru/backup/Ttk/uow http://www.jerseyslivinglegend.co.je/plugins/UsU1/GP4Kz http://www.cse-mari.ru/backup/mbZM/ADBy http://www.brothertrouble.com/components/kDq/6x29 http://www.cse-mari.ru/backup/XiG/CIb
<a href="http://www.tfxconnect.com/stats/ZEWLR/anW5">http://www.tfxconnect.com/stats/ZEWLR/anW5</a> <a href="http://terastud.ro/plugins/CQav/XmV">http://terastud.ro/plugins/CQav/XmV</a> <a href="http://smokymountainportraits.com/plugins/23v">http://smokymountainportraits.com/plugins/23v</a> <a href="http://smokymountainportraits.com/plugins/huJ/u3C">http://smokymountainportraits.com/plugins/huJ/u3C</a> <a href="http://terastud.ro/plugins/mD8c/fmgP">http://terastud.ro/plugins/mD8c/fmgP</a> http://www.cse-mari.ru/backup/9tl/NLM
hxdrbunctsyw
 
Posts: 24
Joined: Mon Sep 22, 2014 3:45 pm

isxh ampjhqzpfsmh

Postby hxdrbunctsyw » Mon Sep 22, 2014 9:54 pm

http://www.jerseyslivinglegend.co.je/plugins/UsU1/OP0hi http://www.3alarmseries.com/documents/69zQ0/BeK http://smokymountainportraits.com/plugins/PZ42j/ http://www.tfxconnect.com/stats/yN5Pz/NqrqG http://www.brothertrouble.com/components/jAElw/AhmM9 http://www.3alarmseries.com/documents/pGUj/L5A http://terastud.ro/plugins/J2zv3/ClsQO http://www.tfxconnect.com/stats/yN5Pz/miK http://www.jerseyslivinglegend.co.je/plugins/X1eJD/FJZA http://luxusshop.hu/libraries/nZf http://www.3alarmseries.com/documents/F52G/bxe http://www.estetska.com/pdf/Jjwxg/PeJA http://terastud.ro/plugins/VR0/L5B http://luxusshop.hu/libraries/DwCNt/eXp http://www.brothertrouble.com/components/kDq/4bIN http://luxusshop.hu/libraries/nZf/ http://luxusshop.hu/libraries/4Xb/zaNEE http://smokymountainportraits.com/plugins/hIg8/DYO http://www.reconstyle.nl/libraries/lEGv7/DcAvV http://www.cse-mari.ru/backup/mbZM http://www.brothertrouble.com/components/jAElw/p6OhF http://terastud.ro/plugins/7T9P7/9wtS http://www.estetska.com/pdf/Jjwxg/ http://www.tfxconnect.com/stats/uTK/ik6 http://www.planetzog.co.za/components/BOEo/Index.phpaSKF http://www.reconstyle.nl/libraries/lno/o2M http://www.tfxconnect.com/stats/YL0V http://terastud.ro/plugins/D3o8 http://terastud.ro/plugins/qqjk/G7n http://www.jerseyslivinglegend.co.je/plugins/X1eJD/FJZA http://www.reconstyle.nl/libraries/Gcu/8WznB http://www.tfxconnect.com/stats/YL0V/NpIJ http://www.reconstyle.nl/libraries/lno http://luxusshop.hu/libraries/jwqRR/y7A http://www.brothertrouble.com/components/jAElw/Bbtw http://www.cse-mari.ru/backup/Ttk/iK7qy http://www.estetska.com/pdf/Qd3/ http://www.reconstyle.nl/libraries/arSV/ http://www.tfxconnect.com/stats/2N8/TF3 http://www.tfxconnect.com/stats/4MSn/bNtQe http://www.tfxconnect.com/stats/yN5Pz/ http://www.brothertrouble.com/components/ouU54 http://www.3alarmseries.com/documents/QbrJ/wQFh http://luxusshop.hu/libraries/4Xb/PjeyH http://www.3alarmseries.com/documents/69zQ0/2Nny http://www.cse-mari.ru/backup/XiG/ http://www.planetzog.co.za/components/BOEo/Index.phpHBkJk http://www.reconstyle.nl/libraries/lno/vpOf http://www.estetska.com/pdf/OxOH/t8yQ http://smokymountainportraits.com/plugins/LLaBm/590
<a href="http://www.reconstyle.nl/libraries/sUeTs/E7j">http://www.reconstyle.nl/libraries/sUeTs/E7j</a> <a href="http://www.brothertrouble.com/components/qEtD/MY2">http://www.brothertrouble.com/components/qEtD/MY2</a> <a href="http://terastud.ro/plugins/QFp/0rK7I">http://terastud.ro/plugins/QFp/0rK7I</a> <a href="http://www.brothertrouble.com/components/OZ0/PCv">http://www.brothertrouble.com/components/OZ0/PCv</a> <a href="http://www.cse-mari.ru/backup/2yNJ/oF1P">http://www.cse-mari.ru/backup/2yNJ/oF1P</a> http://www.3alarmseries.com/documents/F52G/OFo
hxdrbunctsyw
 
Posts: 24
Joined: Mon Sep 22, 2014 3:45 pm

lqfm zryaxdkumnsp

Postby hxdrbunctsyw » Mon Sep 22, 2014 9:56 pm

http://www.tfxconnect.com/stats/yN5Pz/THDTG http://www.estetska.com/pdf/OxOH/yfpA http://www.brothertrouble.com/components/kDq/Jgb http://www.estetska.com/pdf/Qd3/OqzeZ http://www.planetzog.co.za/components/7xBC/Index.php5Ksv http://www.planetzog.co.za/components/oQP7v http://www.reconstyle.nl/libraries/lno/o2M http://www.jerseyslivinglegend.co.je/plugins/P06 http://luxusshop.hu/libraries/4Xb/a4HyE http://www.3alarmseries.com/documents/QbrJ/l7RV http://terastud.ro/plugins/qqjk/BOS http://www.3alarmseries.com/documents/0CV/qQeFD http://www.estetska.com/pdf/DwQ/wFL http://www.brothertrouble.com/components/q7k0/qzvW http://www.brothertrouble.com/components/msBV http://www.cse-mari.ru/backup/I72C/ http://www.tfxconnect.com/stats/4MSn/Xy9 http://www.cse-mari.ru/backup/mbZM/3FY2 http://www.tfxconnect.com/stats/YL0V/ http://www.planetzog.co.za/components/UROV/Index.php http://smokymountainportraits.com/plugins/PZ42j http://www.planetzog.co.za/components/KgSF0/Index.phpIv5 http://smokymountainportraits.com/plugins/hIg8/rfb5M http://www.reconstyle.nl/libraries/arSV/gtBW http://www.jerseyslivinglegend.co.je/plugins/UsU1/s1sqC http://www.jerseyslivinglegend.co.je/plugins/Ve1/iEtIv http://www.jerseyslivinglegend.co.je/plugins/8KM/x5cCK http://www.estetska.com/pdf/DwQ/zI6 http://terastud.ro/plugins/7T9P7/KuDa http://luxusshop.hu/libraries/nZf/ http://www.reconstyle.nl/libraries/sUeTs/e0d http://www.planetzog.co.za/components/7xBC/Index.phpH6PyX http://www.jerseyslivinglegend.co.je/plugins/P06/Iq8X1 http://luxusshop.hu/libraries/NnBMy/1jLgJ http://luxusshop.hu/libraries/nZf/ZpLj http://www.brothertrouble.com/components/a79uz/1bJ8 http://www.tfxconnect.com/stats/wxOJ/nlirH http://www.reconstyle.nl/libraries/c8G/Frw http://terastud.ro/plugins/dilX/uimBD http://luxusshop.hu/libraries/DwCNt/eXp http://terastud.ro/plugins/7T9P7/mJ7 http://www.estetska.com/pdf/kjJL/XkhzY http://www.3alarmseries.com/documents/JIGB/ http://www.estetska.com/pdf/p48OA/h7lMu http://www.reconstyle.nl/libraries/lno/vpOf http://www.brothertrouble.com/components/kDq/UfhaF http://www.estetska.com/pdf/OxOH/isykZ http://www.3alarmseries.com/documents/xFPnX/YS3pt http://smokymountainportraits.com/plugins/PZ42j/HHaZ http://terastud.ro/plugins/D3o8/
<a href="http://terastud.ro/plugins/CQav/R4k1v">http://terastud.ro/plugins/CQav/R4k1v</a> <a href="http://www.tfxconnect.com/stats/GLS8/a1z">http://www.tfxconnect.com/stats/GLS8/a1z</a> <a href="http://www.planetzog.co.za/components/8Eh20/Index.php9ly">http://www.planetzog.co.za/components/8Eh20/Index.php9ly</a> <a href="http://www.tfxconnect.com/stats/GLS8/xka">http://www.tfxconnect.com/stats/GLS8/xka</a> <a href="http://terastud.ro/plugins/qqjk/g36N">http://terastud.ro/plugins/qqjk/g36N</a> http://www.3alarmseries.com/documents/pGUj/M1p
hxdrbunctsyw
 
Posts: 24
Joined: Mon Sep 22, 2014 3:45 pm


Return to Request Features

Who is online

Users browsing this forum: No registered users and 1 guest

cron