head	1.10;
access;
symbols
	REL-09_01_0200:1.10
	REL-09_01_0100:1.10
	REL-09_00_0310:1.10
	REL-09_00_0300:1.10
	REL-09_00_0200:1.10
	REL-09_00_0101:1.10
	REL-09_00_0100:1.10
	REL-08_04_0200:1.8
	REL-08_04_0100:1.8
	REL-08_03_0400:1.8
	REL-08_03_0300:1.8
	REL-08_03_0200:1.7
	REL-08_03_0100:1.7
	REL-08_02_0500:1.7
	REL-08_02_0400:1.7
	REL-08_02_0300:1.7
	REL-08_02_0200:1.6
	REL-08_02_0100:1.5
	REL8_1_STABLE:1.3.0.2
	REL-08_01_0200:1.3
	REL-08_01_0102:1.3
	REL-08_01_0101:1.3
	REL-08_01_0100:1.3
	REL-08_01_0006:1.3
	REL-08_01_0005:1.3
	REL-08_01_0004:1.2;
locks; strict;
comment	@# @;


1.10
date	2010.06.13.14.51.13;	author h-saito;	state Exp;
branches;
next	1.9;

1.9
date	2010.06.13.12.53.27;	author h-saito;	state Exp;
branches;
next	1.8;

1.8
date	2008.07.15.14.21.43;	author dpage;	state Exp;
branches;
next	1.7;

1.7
date	2006.12.14.17.46.35;	author h-saito;	state Exp;
branches;
next	1.6;

1.6
date	2006.09.15.07.52.38;	author dpage;	state Exp;
branches;
next	1.5;

1.5
date	2006.08.31.08.38.20;	author dpage;	state Exp;
branches;
next	1.4;

1.4
date	2006.04.28.07.51.13;	author dpage;	state Exp;
branches;
next	1.3;

1.3
date	2005.10.11.07.47.11;	author petere;	state Exp;
branches;
next	1.2;

1.2
date	2005.09.06.15.19.13;	author dpage;	state Exp;
branches;
next	1.1;

1.1
date	2005.08.27.22.00.54;	author dpage;	state Exp;
branches;
next	;


desc
@@


1.10
log
@add the tips.
Per Dave Page.
@
text
@<!-- saved from url=(0022)http://internet.e-mail -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>psqlODBC FAQ</title>
  </head>

  <body bgcolor="#ffffff" text="#000000" link="#ff0000" vlink="#a00000" alink="#0000ff">
  
    <h1>psqlODBC FAQ</h1>

    <p>Last updated: $Date: 2010/06/13 12:53:27 $</p>

    <P>Current maintainer: Dave Page (<a href="mailto:dpage@@postgresql.org">dpage@@postgresql.org</a>)</p>

    <p>The most recent version of this document can be viewed at <a href=
    "http://psqlodbc.projects.postgresql.org/faq.html">http://psqlodbc.projects.postgresql.org/faq.html</a>.</p>

    <hr>

    <h2>1) General</h2>
    <a href="#1.1">1.1</a>) How do I submit an idea for a new feature or even a patch?<br>
    <a href="#1.2">1.2</a>) Do I even need to compile the driver to use it?<br>
    <a href="#1.3">1.3</a>) How do I install the driver?<br>
    <a href="#1.4">1.4</a>) What operating systems will the driver run on?<br>
    <a href="#1.5">1.5</a>) I've seen other PostgreSQL ODBC drivers out there. Which one is the right one?<br>
    <a href="#1.6">1.6</a>) How do I report a bug or other problems?<br>
    
    <h2>2) Basics</h2>
    <a href="#2.1">2.1</a>) How do I setup a datasource?<br>
    <a href="#2.2">2.2</a>) What's the difference between a File DSN, System DSN, and User DSN?<br>
    <a href="#2.3">2.3</a>) How do I access more advanced driver and/or datasource options?<br>
    <a href="#2.4">2.4</a>) Where can I discover more information about ODBC errors?<br>
    <a href="#2.5">2.5</a>) There are 2 drivers installed - which should I use?<br>

    <h2>3) Connections</h2>
    <a href="#3.1">3.1</a>) Why do I get a message like "Failed to authenticate client as Postgres user using unknown authentication type:be_recvauth: unrecognized message type: 65536" when I try to connect to a datasource?<br>
    <a href="#3.2">3.2</a>) Why do I get a message like "User authentication failed"?<br>
    <a href="#3.3">3.3</a>) What do I need to do to establish a connection to a database?<br>
    <a href="#3.4">3.4</a>) Does psqlODBC support encrypted login for connections?<br>
    
    <h2>4) Advanced</h2>
    <a href="#4.1">4.1</a>) Why do characters with umlauts or accents, or other non-ASCII characters show up in some applications as '?'<br>
    <a href="#4.2">4.2</a>) What data types does the driver support?<br>
    <a href="#4.3">4.3</a>) How do I use the row versioning -OR- why do I get a message about no operator for xid and int4?<br>
    <a href="#4.4">4.4</a>) Can I use large objects or OLE?<br>
    <a href="#4.5">4.5</a>) Why does the PostgreSQL backend complain about running out of memory when some I browse tables with primary keys?<br>
    <a href="#4.6">4.6</a>) How do I get my application to recognize primary keys?<br>
        
    <h2>5) Borland Applications</h2>
    <a href="#5.1">5.1</a>) What driver/datasource options work well with Borland products?<br>
    <a href="#5.2">5.2</a>) # Why do varchar/char datatypes not appear with the correct precision in Borland DBExplorer -OR- why do all varchar/char precisions appear as 128?<br>    
    
    <h2>6) Microsoft Applications</h2>
    <a href="#6.1">6.1</a>) Why don't int4 based aggregates seem to work?<br>
    <a href="#6.2">6.2</a>) Why does Access force me specify the Data Source each time I run my SQL Pass-Thru query?<br>
    <a href="#6.3">6.3</a>) Why does MS Access sometimes complain about a GROUP BY or ORDER BY not being in the target list?<br>
    <a href="#6.4">6.4</a>) Why do I get 'Write Conflict - This record has been changed by another user since you started editing it' in Access 2000 and above?<br>
    <a href="#6.5">6.5</a>) With MS Access, why can't I index on text fields -OR- why do I get "Invalid field definition 'field'" in definition of index or relationship?<br>
    <a href="#6.6">6.6</a>) With MS Access, why can't I GROUP BY,  ORDER BY, or even select WHERE, on columns which are of type "text"?<br>
    <a href="#6.7">6.7</a>) With MS Access, why do I see #Deleted# in rows after some operations?<br>
    <a href="#6.8">6.8</a>) Installing psqlODBC on 64bit Windows.<br>


    <h2>1) General</h2>
 
    <h3><a name="1.1">1.1</a>) How do I submit an idea for a new feature or even a patch?</h3>
    <p>
    You can send mail to <a href="pgsql-odbc@@postgresql.org">pgsql-odbc@@postgresql.org</a>.
    </p>

    <h3><a name="1.2">1.2</a>) Do I even need to compile the driver to use it?</h3>
    <p>
    Probably not. If you are using Windows, all you really need to do is download and run 
    the Full distribution.
    </p>

    <h3><a name="1.3">1.3</a>) How do I install the driver?</h3>
    <p>
    The easiest way to install the driver is to get the Full distribution. Just download, 
    unzip and run the setup program program. The installation is a standard Windows 
    Installer package that will guide you through the process. For future upgrades, 
    the MSI distribution can be used. This is considerably smaller as it does not 
    include the Windows Installer redistributable which you only need install once. 
    The second option is to compile the driver yourself. If you are using this 
    driver on a unix platform, this is currently your only option.
    </p>
    
    <h3><a name="1.4">1.4</a>) What operating systems will the driver run on?</h3>
    <p>
    The psqlODBC executable is written and compiled to run on 32 bit Wintel platform. 
    This includes Windows 95, 98, ME, NT, 2000 and XP. 16 bit applications are capable 
    of using the 32 bit driver but only on these platforms.
    </p>
    <p>
    We do not distribute binaries for Unix. The source code, however has been ported 
    to compile under Unix. There are two driver managers available for Unix, 
    <a href="http://www.unixodbc.org/">UnixODBC</a> and <a href="http://www.iodbc.org/">iODBC</a>.
    </p>
    
    <h3><a name="1.5">1.5</a>) I've seen other PostgreSQL ODBC drivers out there. Which one is the right one?</h3>
    <p>
    This one! This is <i>the</i> official PostgreSQL ODBC driver.
    </p>
    
    <h3><a name="1.6">1.6</a>) How do I report a bug or other problems?</h3>
    <p>
    You can send mail to pgsql-odbc@@postgresql.org When you do, however, you should attach the following:
    </p>
    <ul>
      <li>your ODBC driver version</li>
      <li>your PostgreSQL database version</li>
      <li>any error messages you saw on the screen</li>
      <li>the debug log (mylog_????.log) file (you will have to enable the mylog driver option)</li>
    </ul>
    <p>
    Before posting however, please ensure you are running the latest version of psqlODBC.
    </p>
    
    
    <h2>2) Basics</h2>

    <h3><a name="2.1">2.1</a>) How do I setup a datasource?</h3>
    <p>
    For Windows, use the ODBC Administrator in Control Panel (in some releases it may be found in the 
    Administrative Tools folder. Here you can add, modify, or delete data sources.
    </p>

    <h3><a name="2.2">2.2</a>) What's the difference between a File DSN, System DSN, and User DSN?</h3>
    <p>
    System DSN's and User DSN's differ only in who can access them on the system. 
    A File DSN, however, is not really a datasource. It is a file that contains all 
    the connection parameters used to connect directly to an ODBC driver.
    </p>
    
    <h3><a name="2.3">2.3</a>) How do I access more advanced driver and/or datasource options?</h3>
    <p>
    First, select your favorite datasource to configure. Then in the "PostgreSQL Driver Setup" dialog, 
    select under "Options (Advanced)" either the Driver button or Datasource button. This will bring 
    up another dialog box which contains options you can configure. Refer to the Configuration Help for
    information on all these options.
    </p>
    
    <h3><a name="2.4">2.4</a>) Where can I discover more information about ODBC errors?</h3>
    <p>
    The ODBC driver has an option to log all direct communication (queries, updates, etc.) with 
    the backend as well as error messages and notices in the commlog file. In addition, it now 
    also logs any ODBC connection and statement errors in this file with detailed information. 
    This is good for applications that give misleading, little, or no descriptive information 
    when something goes wrong (VisData is a good example).
    </p>
    
    <h3><a name="2.5">2.5</a>) There are 2 drivers installed - which should I use?</h3>
    <p>
    <b>PostgreSQL Unicode</b> is a Unicode enabled driver that will work well with modern versions of
    applications such as Microsoft Access, with character from a huge range of languages. You should
    use this driver with PostgreSQL databases encoded as 'UNICODE' (more precisely known as 'UTF-8' in
    PostgreSQL).
    </p>
    <p>
    <b>PostgreSQL ANSI</b> is an ANSI driver which is also able to handle some multibyte character sets
    such as EUC_JP, BIG5 and Shift-JIS. This driver should also be used with databases encoded using
    any of the LATIN charactersets.
    </p>
    <p>
    Note that some applications (notably Borland BDE) do not work properly with Unicode ODBC drivers.
    In this case, you must use the ANSI driver.
    </p>

    <h2>3) Connections</h2>
    
    <h3><a name="3.1">3.1</a>) Why do I get a message like "Failed to authenticate client as Postgres user using unknown authentication type:be_recvauth: unrecognized message type: 65536" when I try to connect to a datasource?</h3>
    <p>
    This message comes from the PostgreSQL backend, most likely when there is a protocol 
    mismatch between the ODBC driver and the backend. For example, if you are using PostgreSQL
    6.2 as the backend and try to use the ODBC driver without correctly setting the protocol, 
    this error will occur. You must check the "6.2 protocol" advanced datasource option in 
    the ODBC driver configuration dialog.
    </p>
    <p>
    <b>Note:</b> If you're still running 6.x these days, you really, really, really should upgrade to 8.x as soon as possible!!
    </p>

    <h3><a name="3.2">3.2</a>) Why do I get a message like "User authentication failed"?</h3>
    <p>
    Verify that the database you are trying to connect to exists and is accessible by you. 
    Also, see the above question in regards to user name and password authentication.
    </p>

    <h3><a name="3.3">3.3</a>) What do I need to do to establish a connection to a database?</h3>
    <p>
    ODBC Connection Checklist:
    </p>

    <ul>
      <li>ODBC Driver Data Source Checks
        <ul>
          <li>Valid and resolvable hostname.</li>
          <li>Valid port number (default is 5432).</li>
          <li>Valid and existing database name.</li>
          <li>Valid user name.</li>
          <li>Valid password for the specified user (required if pg_hba.config is set to password authenticate your client).</li>
        </ul>
      <br>&nbsp;</li>

      <li>PostgreSQL Server Checks
        <ul>
          <li>Postmaster must be running.</li>
          <li>Postmaster must run with the -i option , or tcpip=true in postgresql.conf to allow remote connections.</li>
          <li>The pg_hba.conf file in /data directory must be configured to allow your remote host to connect.</li>
        </ul>
      </li>
    </ul>
    
    <h3><a name="3.4">3.4</a>) Does psqlODBC support encrypted login for connections?</h3>
    <p>
    Yes. psqlODBC supports "md5" encrypted logins, but not "crypt" logins. Keep 
    in mind that after login, ODBC sends all queries in plain text, so all you're 
    protecting is your password. Also, support for md5 logins was added in late 2001, 
    so if you have an older version of psqlODBC you may need to update it.
    </p>
    <p>
    <b>Note:</b> As of version 08.01.002, psqlODBC now supports SSL encrypted connections.
    </p>

    <h2>4) Advanced</h2>

    <h3><a name="4.1">4.1</a>) Why do characters with umlauts or accents, or other non-ASCII characters show up in some applications as '?'</h3>
    <p>
    You are probably using the <b>PostgreSQL Unicode</b> driver with non-Unicode,
    8 bit data - for example, from one of the LATIN encodings. You should either 
    use the <b>PostgreSQL ANSI</b> driver, or move your data to a Unicode database.
    </p>
    
    <h3><a name="4.2">4.2</a>) What data types does the driver support?</h3>
    <p>
    The driver provides full support for all PostgreSQL standard data types. 
    These are: bool, int2, int4, int8, float4, float8, date, time, abstime, 
    datetime, timestamp, char, varchar, and text.
    </p>
    <p>
    There is partial support for all other data types. Examples of these: 
    point, circle, box and arrays. String support only is provided for these 
    non-standard types. In other words, they are returned as SQL_VARCHAR and 
    can be displayed and updated like any other data type. The resulting 
    behavior will probably vary some with each application and data type.
    </p>
    <p>
    In the case of int4[] and MS Access 97 it does an effective job. The array 
    can be displayed and updated cleanly. Arithmetic is a little tricky. MS Access 
    complains about "t.a[1]" in the query builder. It does not like the syntax and 
    never sends it to the backend. The work around is to choose the SQL Pass-thru 
    option. This will allow you to build expressions like "t.a[0] * t.a[1]". The 
    hassle is that every time you run the query in Access 97 it prompts you with 
    a database connection dialog.
    </p>
    <p>
    MS Excel in combination w/ MS Query may provide a better solution. It passes 
    every query through. I try to stay away from the more exotic types if I know I 
    am going to expose them to the public.
    </p>
    
    <h3><a name="4.3">4.3</a>) How do I use the row versioning -OR- why do I get a message about no operator for xid and int4?</h3>
    <p>
    Some of the operators are missing in some releases of PostgreSQL (anyone remember 
    which?) so in order to use row versioning, you must overload the int4eq function 
    for use with the xid type. Also, you need to create an operator to compare xid to 
    int4. You must do this for each database you want to use this feature on. This will 
    probably not be necessary in PostgreSQL 6.4 since it will be added. Here are the details:
    </p>
    <pre>    create function int4eq(xid,int4)
        returns bool
        as ''
        language 'internal';

    create operator = (
        leftarg=xid,
        rightarg=int4,
        procedure=int4eq,
        commutator='=',
        negator='<>',
        restrict=eqsel,
        join=eqjoinsel
    );
    </pre>
    
    <h3><a name="4.4">4.4</a>) Can I use large objects or OLE?</h3>
    <p>
    Large objects are mapped to LONGVARBINARY in the driver to allow storing things like OLE 
    objects in Microsoft Access. Multiple SQLPutData and SQLGetData calls are usually used to 
    send and retrieve these objects. The driver creates a new large object and simply inserts 
    its 'identifier' into the respective table. However, since PostgreSQL uses an 'Oid' to identify 
    a Large Object, it is necessary to create a new PostgreSQL type to be able to discriminate 
    between an ordinary Oid and a Large Object Oid. Until this new type becomes an official 
    part of PostgreSQL, it must be added into the desired database and looked up for each connection. 
    The type used in the driver is simply called "lo" and here is the command used to create it:
    </p>
    <pre>    create type lo (
        internallength=4,
        externallength=10,
        input=int4in,
        output=int4out,
        default='',
        passedbyvalue
    );

    create table employee (
        id integer,
        name varchar(30),
        picture lo
    );
    </pre>
    <p>
    Once this is done, simply use the new 'lo' type to define columns in that database. When the driver 
    sees an 'lo' type, it will handle it as SQL_LONGVARBINARY.
    </p>
    <p>
    Another important note is that this new type is lacking in functionality. It will not cleanup after 
    itself on updates and deletes, thus leaving orphans around and using up extra disk space. And 
    currently, PostgreSQL does not support the vacuuming of large objects.
    </p>
    <p>
    It would not be too difficult to write a interim stand-alone cleanup process to run at some interval 
    on the server. It is only a matter of searching pg_attribute for lo data type columns and building 
    a list of lo's by querying each table that contains lo's. Then compare this list with with the xinv.* 
    in pg_class. The xinv.* with out a pointer are orphans and should be dropped.
    </p>
    <p>
    Hopefully in the future, a real large object data type will be available as a base type. But for now, 
    it sure is fun to stick a Word document, Visio document, or AVI of a dancing baby into a database 
    column, even if you will fill up your server's hard disk after a while!
    </p>
    
    <h3><a name="4.5">4.5</a>) Why does the PostgreSQL backend complain about running out of memory when some I browse tables with primary keys?</h3>
    <p>
    The Jet Database Engine (used by Access) and others can use "keysets" to access records. Depending 
    on how many parts are in the key, performance can range from slow to crashing of the backend. Here 
    is a keyset query using 10 rows (the typical keyset amount):
    </p>
    <pre>    -- This is a 3 part key

    select ... from foo where
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 1
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 2
    ...
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 9
        (v1 = "?" AND v2 = "?" AND v3 ="?")    -- line 10
    </pre>
    <p>
    The question marks are replaced with the key values
    </p>
    <p>
    Prior to PostgreSQL 6.4, this was a major problem. But there are at least 2 fixes in place for this as 
    of 6.4. One of the fixes is called KSQO (Keyset Query Optimization). As of 6.4, the driver now turns 
    this on by default, although this can be changed in the Advanced Driver options settings.
    </p>
    
    <h3><a name="4.6">4.6</a>) How do I get my application to recognize primary keys?</h3>
    <p>
    SQLPrimaryKeys() is implemented in the driver. The driver queries the system tables in search 
    of a unique index named with the using "{table}_pkey". For Example:
    </p>
    <pre>    create table foo (
        id integer primary key,
        data varchar(20)
    );
    </pre>


    <h2>5) Borland Applications</h2>

    <h3><a name="5.1">5.1</a>) What driver/datasource options work well with Borland products?</h3>
    <p>
    Consider setting the following advanced driver options if using Borland:
    </p>
    <ul>
      <li>Check Text as LongVarchar</li>
      <li>Uncheck Unknowns as LongVarchar</li>
      <li>Parse Statements option: Enable it, if using a protocol earlier than PostgreSQL 6.4</li>
      <li>Unknown Sizes Options: Set to "Longest"</li>
    </ul>

    <h3><a name="5.1">5.1</a>) Why do varchar/char datatypes not appear with the correct precision in Borland DBExplorer -OR- why do all varchar/char precisions appear as 128?</h3>
    <p>
    When using the 6.4 protocol, this problem should not be an issue.
    </p>
    <p>
    Prior to the PostgreSQL 6.4 protocol, the backend did not return the size of 
    varchar/char datatypes in a query result and Borland relies heavily on this 
    for both simple queries and the data dictionary import. Therefore, there are 
    several driver options that were developed to help out with this.
    </p>
    <ul>
      <li>Parse Statements option -- driver parses the SQL statement and retrieves 
      characteristics such as precision, nullability, aliases, etc. for the columns.</li>
      <li>Unknown Sizes option -- "longest" will return the precision based on the 
      longest data of all the rows in the result set.</li>
    </ul>
    <p>
    Currently, if the parse statements option is enabled, the parser will fallback 
    on executing the statement if it cannot deal with a particular column. Therefore, 
    it is a good idea to set the unknown sizes to "longest" as well.
    </p>
    
    
    <h2>6) Microsoft Applications</h2>
    
    <h3><a name="6.1">6.1</a>) Why don't int4 based aggregates seem to work?</h3>
    <p>
    Some Aggregates such as sum(int4) and avg(int4) return results using the numeric 
    datatype. This is perfectly legal according to the SQL spec and is done to prevent 
    overflows and other problems, but unfortunately Microsoft's ActiveX Data Objects don't 
    seem to like it. There are two workarounds:
    </p>
    <ul>
      <li>Cast the result to an int4 e.g. SELECT avg(fieldname)::int4 FROM tablename</li>
      <li>Set the ADO CursorLocation to AdUseClient. Note: This will produce a read only recordset.</li>
    </ul>
    
    <h3><a name="6.2">6.2</a>) Why does Access force me specify the Data Source each time I run my SQL Pass-Thru query?</h3>
    <p>
    There is a way to specify a Data Source in the query properties so it doesn't ask you 
    each time. Under the view menu, select properties. For the "ODBC Connect Str" property 
    right after "ODBC;" add "DSN=&lt;your_datasource_name_here&gt;". You can also add other 
    properties if you like such as "ODBC;DSN=my_dsn;UID=me;PWD=test".
    </p>

    <h3><a name="6.3">6.3</a>) Why does MS Access sometimes complain about a GROUP BY or ORDER BY not being in the target list?</h3>
    <p>
    This message comes from the PostgreSQL backend. PostgreSQL currently requires fields 
    in the ORDER BY and GROUP BY clauses to be included in the target list. However, 
    this restriction has been lifted in PostgreSQL 6.4+
    </p>
    <p>
    Older versions of the Microsoft Jet Database Engine, that Access is built on, has 
    some problems that can cause this to occur. Access will insist on throwing in an 
    order by clause in a join query, even if you are not sorting on anything. Even with 
    PostgreSQL 6.4+, the query may no longer error out, BUT it would be sorted in a way 
    you may not want, and there would be no way to change it. To fix this problem, you 
    need to update the Jet database engine to version 3.51. It is available at no charge 
    from Microsoft. Click <a href="http://www.microsoft.com/data">here to download</a> 
    the latest Jet Engine from the Microsoft support site.
    </p>
    
    <h3><a name="6.4">6.4</a>) Why do I get 'Write Conflict - This record has been changed by another user since you started editing it' in Access 2000 and above?</h3>
    <p>
    <b>Contributed by Michael Zedeler (michael.zedeler@@tirush.dk)</b>
    </p>
    <p>
    If you get the following message: "Write Conflict - This record has been changed by 
    another user since you started editing it. [...]" from Access 2000, its likely to be 
    a problem that arises from differing standards between Access and PostgreSQL.
    </p>
    <p>
    From old times, according to some SQL standard, an empty space is by definition equal 
    to NULL. This disposition has caused many grievances over the years, so PostgreSQL rectifies 
    this by deviating from the standard. In PostgreSQL, NULL is NULL and the empty string is the 
    empty string.
    </p>
    <p>
    So when Access retrieves a row from PostgreSQL with fields containing the empty string, it 
    automatically translates them into NULL values. When you try updating this row, the query sent 
    from Access 2000 to PostgreSQL will fail to update the row. An example:
    </p>
    <p>
    You have inserted the following row into table a:
    </p>
    <pre>        id  | name----+-------------------------  1 | <- contains the empty string. Not NULL.
    </pre>
    <p>
    And then you retrieve the row using Access 2000, subsequently inserting the value "Smartypants" 
    in the "name" field.
    </p>
    <p>
    You would expect Access 2000 to send the following query to PostgreSQL:
    </p>
    <code>
    UPDATE a SET name = 'Smartypants' WHERE id = 1 AND name = ''
    </code>
    <p>
    (The extra "AND name = ''" is included to avoid updates in case that some other user has 
    already updated the given row.)
    </p>
    <p>
    But what Access 2000 actually sends is:
    </p>
    <code>
    UPDATE a SET name = 'Smartypants' WHERE id = 1 AND name IS NULL
    </code>
    <p>
    That query fails because NULL is not being treated as the empty string by PostgreSQL.
    </p>
    <p>
    <b>How to fix the problem</b>
    </p>
    <p>
    I haven't found any way around it, but to stop using empty strings in character fields.
    </p>
    <p>
    The problem only arises when other systems inserts data into PostgreSQL tables, so 
    you'll have to make those systems start using NULL in stead of the empty string, where 
    necessary. When Access 2000 inserts data, it will always translate the empty string into 
    NULL, thus maintaining data that are consistent with the (old?) SQL standard.
    </p>
    <p>
    PostgreSQL 7.2 and above can cause similar problems but for different reasons:
    </p>
    <p>
    <b>Contributed by Sam Hokin (sam@@ims.net)</b>
    </p>
    <p>
    The new PostgreSQL timestamp data type defaults to microsecond 
    precision.  This means that timestamp values are stored like 2002-05-22 
    09:00:00.123456-05.  However, Access does not support the extra precision, 
    so the value that Access uses is 2002-05-22 09:00:00-05.  When one tries to 
    update a record, one gets the error message above because the value that 
    Access uses in its UPDATE query does not match the value in the PostgreSQL 
    table, similar to the NULL vs. empty string conflict that is already 
    reported in this FAQ entry.
    </p>
    <p>
    <b>How to fix the problem</b>
    </p>
    <p>
    The simple fix is to use timestamp(0) rather than timestamp.  Otherwise, 
    one must make sure that all timestamp values entered into the PostgreSQL 
    table have zero fractional second value.
    </p>
    <p>
    Incidentally, this problem occurs in Access 97 as well as Access 2000.
    </p>
    <p>
    <b>Contributed by Steven Citron-Pousty (Steven.Citron-Pousty@@yale.edu)</b>
    </p>
    <p>
    Another way around the issue noted here in access2k and 7.2 is to use a 
    query behind your data view that excludes the timestamp columns. In our 
    case the timestamps are autogenerated so we don't even need to 
    see them. So if you don't need to edit the timestamp value hide the 
    column by making a query without the data value.
    </p>
    
    <h3><a name="6.5">6.5</a>) With MS Access, why can't I index on text fields -OR- why do I get "Invalid field definition 'field'" in definition of index or relationship?</h3>
    <p>
    Text fields are mapped to SQL_LONGVARCHAR by default. As a result MS Access 
    treats these colomns as "Memo" types. The good news is that you can store up 
    to the PostgreSQL block size limit in a text column. PostgreSQL has a tuple 
    limit of just under 8k prior to version 7.1 which includes a new feature 
    called TOAST which allows the storage of much larger strings.
    </p>
    <p>
    You can change the mapping of Text fields to SQL_VARCHAR by unchecking the 
    Advanced driver option "Text as LongVarchar" under Data Type Options. This 
    should allow text fields to be used but you will be limited to the maximum 
    size of a varchar.
    </p>
    
    <h3><a name="6.6">6.6</a>) With MS Access, why can't I GROUP BY,  ORDER BY, or even select WHERE, on columns which are of type "text"?</h3>
    <p>
    Text fields are mapped to SQL_LONGVARCHAR by default. As a result MS Access 
    treats these colomns as "Memo" types. The good news is that you can store up 
    to the PostgreSQL block size limit in a text column. PostgreSQL has a tuple 
    limit of just under 8k prior to version 7.1 which includes a new feature 
    called TOAST which allows the storage of much larger strings.
    </p>
    <p>
    You can change the mapping of Text fields to SQL_VARCHAR by unchecking the 
    Advanced driver option "Text as LongVarchar" under Data Type Options. This 
    should allow text fields to be used.
    </p>
    
    <h3><a name="6.7">6.7</a>) With MS Access, why do I see #Deleted# in rows after some operations?</h3>
    <p>
    This commonly occurs if you have used numeric or int8 (bigint) columns as your 
    primary key. In Access, an Int is a 16 bit value and a Long Int is a 32 bit value,
    unlike PostgreSQL in which an int is a 32 bit value and a bigint is 64 bit. Access
    sees the int8/numeric key as a floating point value, which it cannot use as a key.
    To resolve the problem, stick to int4 if you need numerical primary keys. For more
    intofmation, please see <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;128809">
    Microsoft KB article #128809</a>.
    </p>

    <h3><a name="6.8">6.8</a>) Installing psqlODBC on 64bit Windows</h3>
    <p>
    <b>Contributed by Mark Wood (mw@@mcwood.co.uk)</b><br>
    <p>
    Though you can install 32 bit ODBC drivers on Win X64 as usual, you can't 
    configure 32-bit DSNs via oridinary control panel or ODBC datasource
    administrator.
    <p>
    <b>How to configure 32 bit ODBC drivers on Win x64</b><br>
    <p>
    Configure ODBC DSN from <b>%SystemRoot%\syswow64\odbcad32.exe.&nbsp; </b>
    Click<br>
    <p>
    &nbsp&nbsp Start-&gt;Run<br>
    &nbsp;&nbsp; Enter:<b> %SystemRoot%\syswow64\odbcad32.exe</b><br>
    &nbsp&nbsp Hit return<br>
    <br>
    This looks the same as the driver manager you might run from the control 
    panel, but is for managing 32bit drivers. If you run odbcad32.exe from the 
    System32 directory, you are actually running the 64bit driver manager.<br>
    <br>
    <b>What is WOW64?</b><br>
    I would probably remove the rest of the info if possible, and just include a 
    link to more information on WOW64 - maybe<br>
    <a href="http://msdn.microsoft.com/en-us/library/aa384274(v=VS.85).aspx">
    http://msdn.microsoft.com/en-us/library/aa384274(v=VS.85).aspx</a> for 
    example.<br>
    <br>
    <b>What's and why WOW64</b><br>
    <a href="http://forums.techarena.in/operating-systems/1160164.htm">http://forums.techarena.in/operating-systems/1160164.htm</a><br>
    <br>
    WoW64 stands for &quot;Windows on 64-bit Windows&quot;, and it contains all the 32-bit 
    binary files required for compatibility, which run on top of the<br>
    64 bit Windows. So, yeah&quot; it looks like a double copy of everything in 
    System32 (which despite the directory name, are actually 64-bit binaries).<br>
    <br>
    If you are running 32 bit Windows then finding this SysWoW64 directory is a 
    bit weird ...<br>
    <br>
    WOW64 knows that the Setup wizard is a 32-bit application running within an 
    emulator. It also knows that 64- and 32-bit code cannot be mixed. As such, 
    the WOW64 emulator aliases an alias to the \Windows\SysWOW64 folder. This 
    means that any time a 32-bit application needs to read or write anything to 
    or from the \Windows\System32 folder, the WOW64 emulator transparently 
    redirects the request to the \Windows\SysWOW64 folder.<br>
    <br>
    Microsoft offers a set of 32 bit executables in the WoW(Windows on Windows) 
    directory of the system, for a Windows Vista 64 bit Operating System.<br>
    <br>
    To setup DSN for 32-bit application you must use: <b>%WINDIR%\SysWOW64\odbcad32.exe</b><br>
    <br>
    and for 64-bit application you must use: <b>%WINDIR%\System32\odbcad32.exe</b><br>
    <br>
    So, to run a 32 bit application, we would need to modify the env PATH 
    variable and put SysWOW64 before system32.<br>
    <br>
    Roughly the steps would be<br>
    1. Start <b>%windir%\SysWoW64\cmd.exe</b><br>
    2. set <b>PATH=%systemroot%\SysWOW64;%PATH%</b><br>
    3. Run the application.<br>
    4. After application has completed, reset PATH variable if required.<br>
    <br>
    Hope this was helpful.<br>
    Or, if the application can't be run from a shell then you could modify
    the PATH variable directly from System Properties &gt; Advanced Tab &gt;
    Environmental Variable &gt; System variable.<br>
    Edit the PATH variable accordingly and reboot the system for the changes
    to take effect.<br>
    <br>
    And also check the related threads :<br>
    <br>
    * Adminpak SP2 , Windows Server x64 SP2<br>
    &lt;<a href="http://forums.techarena.in/windows-x64-edition/810091.htm">http://forums.techarena.in/windows-x64-edition/810091.htm</a>&gt;<br>
    * Need Help Registering DLLs<br>
    &lt;<a href="http://forums.techarena.in/windows-x64-edition/804399.htm">http://forums.techarena.in/windows-x64-edition/804399.htm</a>&gt;<br>
    * Certificate Services Web interface and Win2k3 x64/AMD64 edition<br>
    &lt;<a href="http://forums.techarena.in/server-security/598973.htm">http://forums.techarena.in/server-security/598973.htm</a>&gt;<br>
    <br>
    Documentation on what you can expect you registry to show after
    installation using postgresql dbc msi<br>
    <br>
    <a href="http://archives.postgresql.org/pgsql-interfaces/2001-01/msg00177.php">
    http://archives.postgresql.org/pgsql-interfaces/2001-01/msg00177.php</a><br>
    <br>
    There are two versions of the ODBC driver at ftp.postgresql.org: one is
    the full package including installer, the other is just the driver itself.<br>
    Once you have installed with installer once, you can upgrade by just copying 
    new versions of the driver to windows\system.<br>
    If for some reason you cannot get the installer to work, you can do the 
    install by hand with regedit.<br>
    <br>
    Find the key <b>HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI </b>and add the 
    following:<br>
    <br>
    REGEDIT4<br>
    <br>
    <b>[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\PostgreSQL]<br>
    </b>
    &quot;Setup&quot;=&quot;C:\\WINDOWS\\SYSTEM\\PSQLODBC.DLL&quot;<br>
    &quot;Driver&quot;=&quot;C:\\WINDOWS\\SYSTEM\\PSQLODBC.DLL&quot;<br>
    &quot;APILevel&quot;=&quot;1&quot;<br>
    &quot;ConnectFunctions&quot;=&quot;YYN&quot;<br>
    &quot;CommLog&quot;=&quot;0&quot;<br>
    &quot;Optimizer&quot;=&quot;0&quot;<br>
    &quot;DriverODBCVer&quot;=&quot;02.00&quot;<br>
    &quot;FileUsage&quot;=&quot;0&quot;<br>
    &quot;SQLLevel&quot;=&quot;1&quot;<br>
    &quot;UsageCount&quot;=dword:00000001<br>
    &quot;Fetch&quot;=&quot;100&quot;<br>
    &quot;UniqueIndex&quot;=&quot;1&quot;<br>
    &quot;ReadOnly&quot;=&quot;0&quot;<br>
    &quot;UseCursors&quot;=&quot;0&quot;<br>
    &quot;UnknownSizes&quot;=&quot;0&quot;<br>
    &quot;TextAsLongVarchar&quot;=&quot;0&quot;<br>
    &quot;UnknownsAsLongVarchar&quot;=&quot;0&quot;<br>
    &quot;MaxVarcharSize&quot;=&quot;254&quot;<br>
    &quot;MaxLongVarcharSize&quot;=&quot;4094&quot;<br>
    &quot;ConnSettings&quot;=&quot;&quot;<br>
    &quot;UseDeclareFetch&quot;=&quot;0&quot;<br>
    &quot;BoolsAsChar&quot;=&quot;0&quot;<br>
    &quot;ExtraSysTablePrefixes&quot;=&quot;dd_;&quot;<br>
    &quot;Parse&quot;=&quot;1&quot;<br>
    &quot;Ksqo&quot;=&quot;1&quot;<br>
    &quot;CancelAsFreeStmt&quot;=&quot;0&quot;<b><br>
    </b>
    <br>
    (Note: check the above paths for your system)<br>
    <br>
    Find the key <b>HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC</b> Drivers and 
    add an entry &quot;<b>PostgreSQL= Installed</b>&quot;.<br>
    <br>
    From the Desk of Mark Wood (mw@@mcwood.co.uk ) 
    20100524<br>
&nbsp;</p>

</body>
</head>@


1.9
log
@add faq.(6.8)
"Why can't we set up DSN on WIN x64."
Contributed by Mark Wood.
@
text
@d13 1
a13 1
    <p>Last updated: $Date: 2010/06/12 00:42:00 $</p>
d63 1
a63 1
    <a href="#6.8">6.8</a>) Why can't we set up DSN on WIN x64.<br>
d584 1
a584 1
    <h3><a name="6.8">6.8</a>) Why can't we setup DSN on WIN x64?</h3>
d594 2
a595 1
    Configure ODBC DSN from <b>%SystemRoot%\syswow64\odbcad32.exe.</b><br>
d597 2
a598 2
    &nbsp&nbsp Start|Run<br>
    &nbsp&nbsp Paste <b>%SystemRoot%\syswow64\odbcad32.exe</b><br>
d601 10
a612 1
    <br>
d631 1
a631 1
    directory of the system, for a Windows Vista 64 bit Operating System,<br>
@


1.8
log
@Note that the data sources applet may be in the Administrative Tools folder on some versions of Windows
@
text
@d1 710
a710 588
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>psqlODBC FAQ</title>
  </head>

  <body bgcolor="#ffffff" text="#000000" link="#ff0000" vlink="#a00000" alink="#0000ff">
  
    <h1>psqlODBC FAQ</h1>

    <p>Last updated: $Date: 2006/12/14 17:46:35 $</p>

    <P>Current maintainer: Dave Page (<a href="mailto:dpage@@postgresql.org">dpage@@postgresql.org</a>)</p>

    <p>The most recent version of this document can be viewed at <a href=
    "http://psqlodbc.projects.postgresql.org/faq.html">http://psqlodbc.projects.postgresql.org/faq.html</a>.</p>

    <hr>

    <h2>1) General</h2>
    <a href="#1.1">1.1</a>) How do I submit an idea for a new feature or even a patch?<br>
    <a href="#1.2">1.2</a>) Do I even need to compile the driver to use it?<br>
    <a href="#1.3">1.3</a>) How do I install the driver?<br>
    <a href="#1.4">1.4</a>) What operating systems will the driver run on?<br>
    <a href="#1.5">1.5</a>) I've seen other PostgreSQL ODBC drivers out there. Which one is the right one?<br>
    <a href="#1.6">1.6</a>) How do I report a bug or other problems?<br>
    
    <h2>2) Basics</h2>
    <a href="#2.1">2.1</a>) How do I setup a datasource?<br>
    <a href="#2.2">2.2</a>) What's the difference between a File DSN, System DSN, and User DSN?<br>
    <a href="#2.3">2.3</a>) How do I access more advanced driver and/or datasource options?<br>
    <a href="#2.4">2.4</a>) Where can I discover more information about ODBC errors?<br>
    <a href="#2.5">2.5</a>) There are 2 drivers installed - which should I use?<br>

    <h2>3) Connections</h2>
    <a href="#3.1">3.1</a>) Why do I get a message like "Failed to authenticate client as Postgres user using unknown authentication type:be_recvauth: unrecognized message type: 65536" when I try to connect to a datasource?<br>
    <a href="#3.2">3.2</a>) Why do I get a message like "User authentication failed"?<br>
    <a href="#3.3">3.3</a>) What do I need to do to establish a connection to a database?<br>
    <a href="#3.4">3.4</a>) Does psqlODBC support encrypted login for connections?<br>
    
    <h2>4) Advanced</h2>
    <a href="#4.1">4.1</a>) Why do characters with umlauts or accents, or other non-ASCII characters show up in some applications as '?'<br>
    <a href="#4.2">4.2</a>) What data types does the driver support?<br>
    <a href="#4.3">4.3</a>) How do I use the row versioning -OR- why do I get a message about no operator for xid and int4?<br>
    <a href="#4.4">4.4</a>) Can I use large objects or OLE?<br>
    <a href="#4.5">4.5</a>) Why does the PostgreSQL backend complain about running out of memory when some I browse tables with primary keys?<br>
    <a href="#4.6">4.6</a>) How do I get my application to recognize primary keys?<br>
        
    <h2>5) Borland Applications</h2>
    <a href="#5.1">5.1</a>) What driver/datasource options work well with Borland products?<br>
    <a href="#5.2">5.2</a>) # Why do varchar/char datatypes not appear with the correct precision in Borland DBExplorer -OR- why do all varchar/char precisions appear as 128?<br>    
    
    <h2>6) Microsoft Applications</h2>
    <a href="#6.1">6.1</a>) Why don't int4 based aggregates seem to work?<br>
    <a href="#6.2">6.2</a>) Why does Access force me specify the Data Source each time I run my SQL Pass-Thru query?<br>
    <a href="#6.3">6.3</a>) Why does MS Access sometimes complain about a GROUP BY or ORDER BY not being in the target list?<br>
    <a href="#6.4">6.4</a>) Why do I get 'Write Conflict - This record has been changed by another user since you started editing it' in Access 2000 and above?<br>
    <a href="#6.5">6.5</a>) With MS Access, why can't I index on text fields -OR- why do I get "Invalid field definition 'field'" in definition of index or relationship?<br>
    <a href="#6.6">6.6</a>) With MS Access, why can't I GROUP BY,  ORDER BY, or even select WHERE, on columns which are of type "text"?<br>
    <a href="#6.7">6.7</a>) With MS Access, why do I see #Deleted# in rows after some operations?<br>


    <h2>1) General</h2>
 
    <h3><a name="1.1">1.1</a>) How do I submit an idea for a new feature or even a patch?</h3>
    <p>
    You can send mail to <a href="pgsql-odbc@@postgresql.org">pgsql-odbc@@postgresql.org</a>.
    </p>

    <h3><a name="1.2">1.2</a>) Do I even need to compile the driver to use it?</h3>
    <p>
    Probably not. If you are using Windows, all you really need to do is download and run 
    the Full distribution.
    </p>

    <h3><a name="1.3">1.3</a>) How do I install the driver?</h3>
    <p>
    The easiest way to install the driver is to get the Full distribution. Just download, 
    unzip and run the setup program program. The installation is a standard Windows 
    Installer package that will guide you through the process. For future upgrades, 
    the MSI distribution can be used. This is considerably smaller as it does not 
    include the Windows Installer redistributable which you only need install once. 
    The second option is to compile the driver yourself. If you are using this 
    driver on a unix platform, this is currently your only option.
    </p>
    
    <h3><a name="1.4">1.4</a>) What operating systems will the driver run on?</h3>
    <p>
    The psqlODBC executable is written and compiled to run on 32 bit Wintel platform. 
    This includes Windows 95, 98, ME, NT, 2000 and XP. 16 bit applications are capable 
    of using the 32 bit driver but only on these platforms.
    </p>
    <p>
    We do not distribute binaries for Unix. The source code, however has been ported 
    to compile under Unix. There are two driver managers available for Unix, 
    <a href="http://www.unixodbc.org/">UnixODBC</a> and <a href="http://www.iodbc.org/">iODBC</a>.
    </p>
    
    <h3><a name="1.5">1.5</a>) I've seen other PostgreSQL ODBC drivers out there. Which one is the right one?</h3>
    <p>
    This one! This is <i>the</i> official PostgreSQL ODBC driver.
    </p>
    
    <h3><a name="1.6">1.6</a>) How do I report a bug or other problems?</h3>
    <p>
    You can send mail to pgsql-odbc@@postgresql.org When you do, however, you should attach the following:
    </p>
    <ul>
      <li>your ODBC driver version</li>
      <li>your PostgreSQL database version</li>
      <li>any error messages you saw on the screen</li>
      <li>the debug log (mylog_????.log) file (you will have to enable the mylog driver option)</li>
    </ul>
    <p>
    Before posting however, please ensure you are running the latest version of psqlODBC.
    </p>
    
    
    <h2>2) Basics</h2>

    <h3><a name="2.1">2.1</a>) How do I setup a datasource?</h3>
    <p>
    For Windows, use the ODBC Administrator in Control Panel (in some releases it may be found in the 
    Administrative Tools folder. Here you can add, modify, or delete data sources.
    </p>

    <h3><a name="2.2">2.2</a>) What's the difference between a File DSN, System DSN, and User DSN?</h3>
    <p>
    System DSN's and User DSN's differ only in who can access them on the system. 
    A File DSN, however, is not really a datasource. It is a file that contains all 
    the connection parameters used to connect directly to an ODBC driver.
    </p>
    
    <h3><a name="2.3">2.3</a>) How do I access more advanced driver and/or datasource options?</h3>
    <p>
    First, select your favorite datasource to configure. Then in the "PostgreSQL Driver Setup" dialog, 
    select under "Options (Advanced)" either the Driver button or Datasource button. This will bring 
    up another dialog box which contains options you can configure. Refer to the Configuration Help for
    information on all these options.
    </p>
    
    <h3><a name="2.4">2.4</a>) Where can I discover more information about ODBC errors?</h3>
    <p>
    The ODBC driver has an option to log all direct communication (queries, updates, etc.) with 
    the backend as well as error messages and notices in the commlog file. In addition, it now 
    also logs any ODBC connection and statement errors in this file with detailed information. 
    This is good for applications that give misleading, little, or no descriptive information 
    when something goes wrong (VisData is a good example).
    </p>
    
    <h3><a name="2.5">2.5</a>) There are 2 drivers installed - which should I use?</h3>
    <p>
    <b>PostgreSQL Unicode</b> is a Unicode enabled driver that will work well with modern versions of
    applications such as Microsoft Access, with character from a huge range of languages. You should
    use this driver with PostgreSQL databases encoded as 'UNICODE' (more precisely known as 'UTF-8' in
    PostgreSQL).
    </p>
    <p>
    <b>PostgreSQL ANSI</b> is an ANSI driver which is also able to handle some multibyte character sets
    such as EUC_JP, BIG5 and Shift-JIS. This driver should also be used with databases encoded using
    any of the LATIN charactersets.
    </p>
    <p>
    Note that some applications (notably Borland BDE) do not work properly with Unicode ODBC drivers.
    In this case, you must use the ANSI driver.
    </p>

    <h2>3) Connections</h2>
    
    <h3><a name="3.1">3.1</a>) Why do I get a message like "Failed to authenticate client as Postgres user using unknown authentication type:be_recvauth: unrecognized message type: 65536" when I try to connect to a datasource?</h3>
    <p>
    This message comes from the PostgreSQL backend, most likely when there is a protocol 
    mismatch between the ODBC driver and the backend. For example, if you are using PostgreSQL
    6.2 as the backend and try to use the ODBC driver without correctly setting the protocol, 
    this error will occur. You must check the "6.2 protocol" advanced datasource option in 
    the ODBC driver configuration dialog.
    </p>
    <p>
    <b>Note:</b> If you're still running 6.x these days, you really, really, really should upgrade to 8.x as soon as possible!!
    </p>

    <h3><a name="3.2">3.2</a>) Why do I get a message like "User authentication failed"?</h3>
    <p>
    Verify that the database you are trying to connect to exists and is accessible by you. 
    Also, see the above question in regards to user name and password authentication.
    </p>

    <h3><a name="3.3">3.3</a>) What do I need to do to establish a connection to a database?</h3>
    <p>
    ODBC Connection Checklist:
    </p>

    <ul>
      <li>ODBC Driver Data Source Checks
        <ul>
          <li>Valid and resolvable hostname.</li>
          <li>Valid port number (default is 5432).</li>
          <li>Valid and existing database name.</li>
          <li>Valid user name.</li>
          <li>Valid password for the specified user (required if pg_hba.config is set to password authenticate your client).</li>
        </ul>
      <br>&nbsp;</li>

      <li>PostgreSQL Server Checks
        <ul>
          <li>Postmaster must be running.</li>
          <li>Postmaster must run with the -i option , or tcpip=true in postgresql.conf to allow remote connections.</li>
          <li>The pg_hba.conf file in /data directory must be configured to allow your remote host to connect.</li>
        </ul>
      </li>
    </ul>
    
    <h3><a name="3.4">3.4</a>) Does psqlODBC support encrypted login for connections?</h3>
    <p>
    Yes. psqlODBC supports "md5" encrypted logins, but not "crypt" logins. Keep 
    in mind that after login, ODBC sends all queries in plain text, so all you're 
    protecting is your password. Also, support for md5 logins was added in late 2001, 
    so if you have an older version of psqlODBC you may need to update it.
    </p>
    <p>
    <b>Note:</b> As of version 08.01.002, psqlODBC now supports SSL encrypted connections.
    </p>

    <h2>4) Advanced</h2>

    <h3><a name="4.1">4.1</a>) Why do characters with umlauts or accents, or other non-ASCII characters show up in some applications as '?'</h3>
    <p>
    You are probably using the <b>PostgreSQL Unicode</b> driver with non-Unicode,
    8 bit data - for example, from one of the LATIN encodings. You should either 
    use the <b>PostgreSQL ANSI</b> driver, or move your data to a Unicode database.
    </p>
    
    <h3><a name="4.2">4.2</a>) What data types does the driver support?</h3>
    <p>
    The driver provides full support for all PostgreSQL standard data types. 
    These are: bool, int2, int4, int8, float4, float8, date, time, abstime, 
    datetime, timestamp, char, varchar, and text.
    </p>
    <p>
    There is partial support for all other data types. Examples of these: 
    point, circle, box and arrays. String support only is provided for these 
    non-standard types. In other words, they are returned as SQL_VARCHAR and 
    can be displayed and updated like any other data type. The resulting 
    behavior will probably vary some with each application and data type.
    </p>
    <p>
    In the case of int4[] and MS Access 97 it does an effective job. The array 
    can be displayed and updated cleanly. Arithmetic is a little tricky. MS Access 
    complains about "t.a[1]" in the query builder. It does not like the syntax and 
    never sends it to the backend. The work around is to choose the SQL Pass-thru 
    option. This will allow you to build expressions like "t.a[0] * t.a[1]". The 
    hassle is that every time you run the query in Access 97 it prompts you with 
    a database connection dialog.
    </p>
    <p>
    MS Excel in combination w/ MS Query may provide a better solution. It passes 
    every query through. I try to stay away from the more exotic types if I know I 
    am going to expose them to the public.
    </p>
    
    <h3><a name="4.3">4.3</a>) How do I use the row versioning -OR- why do I get a message about no operator for xid and int4?</h3>
    <p>
    Some of the operators are missing in some releases of PostgreSQL (anyone remember 
    which?) so in order to use row versioning, you must overload the int4eq function 
    for use with the xid type. Also, you need to create an operator to compare xid to 
    int4. You must do this for each database you want to use this feature on. This will 
    probably not be necessary in PostgreSQL 6.4 since it will be added. Here are the details:
    </p>
    <pre>
    create function int4eq(xid,int4)
        returns bool
        as ''
        language 'internal';

    create operator = (
        leftarg=xid,
        rightarg=int4,
        procedure=int4eq,
        commutator='=',
        negator='<>',
        restrict=eqsel,
        join=eqjoinsel
    );
    </pre>
    
    <h3><a name="4.4">4.4</a>) Can I use large objects or OLE?</h3>
    <p>
    Large objects are mapped to LONGVARBINARY in the driver to allow storing things like OLE 
    objects in Microsoft Access. Multiple SQLPutData and SQLGetData calls are usually used to 
    send and retrieve these objects. The driver creates a new large object and simply inserts 
    its 'identifier' into the respective table. However, since PostgreSQL uses an 'Oid' to identify 
    a Large Object, it is necessary to create a new PostgreSQL type to be able to discriminate 
    between an ordinary Oid and a Large Object Oid. Until this new type becomes an official 
    part of PostgreSQL, it must be added into the desired database and looked up for each connection. 
    The type used in the driver is simply called "lo" and here is the command used to create it:
    </p>
    <pre>
    create type lo (
        internallength=4,
        externallength=10,
        input=int4in,
        output=int4out,
        default='',
        passedbyvalue
    );

    create table employee (
        id integer,
        name varchar(30),
        picture lo
    );
    </pre>
    <p>
    Once this is done, simply use the new 'lo' type to define columns in that database. When the driver 
    sees an 'lo' type, it will handle it as SQL_LONGVARBINARY.
    </p>
    <p>
    Another important note is that this new type is lacking in functionality. It will not cleanup after 
    itself on updates and deletes, thus leaving orphans around and using up extra disk space. And 
    currently, PostgreSQL does not support the vacuuming of large objects.
    </p>
    <p>
    It would not be too difficult to write a interim stand-alone cleanup process to run at some interval 
    on the server. It is only a matter of searching pg_attribute for lo data type columns and building 
    a list of lo's by querying each table that contains lo's. Then compare this list with with the xinv.* 
    in pg_class. The xinv.* with out a pointer are orphans and should be dropped.
    </p>
    <p>
    Hopefully in the future, a real large object data type will be available as a base type. But for now, 
    it sure is fun to stick a Word document, Visio document, or AVI of a dancing baby into a database 
    column, even if you will fill up your server's hard disk after a while!
    </p>
    
    <h3><a name="4.5">4.5</a>) Why does the PostgreSQL backend complain about running out of memory when some I browse tables with primary keys?</h3>
    <p>
    The Jet Database Engine (used by Access) and others can use "keysets" to access records. Depending 
    on how many parts are in the key, performance can range from slow to crashing of the backend. Here 
    is a keyset query using 10 rows (the typical keyset amount):
    </p>
    <pre>
    -- This is a 3 part key

    select ... from foo where
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 1
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 2
    ...
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 9
        (v1 = "?" AND v2 = "?" AND v3 ="?")    -- line 10
    </pre>
    <p>
    The question marks are replaced with the key values
    </p>
    <p>
    Prior to PostgreSQL 6.4, this was a major problem. But there are at least 2 fixes in place for this as 
    of 6.4. One of the fixes is called KSQO (Keyset Query Optimization). As of 6.4, the driver now turns 
    this on by default, although this can be changed in the Advanced Driver options settings.
    </p>
    
    <h3><a name="4.6">4.6</a>) How do I get my application to recognize primary keys?</h3>
    <p>
    SQLPrimaryKeys() is implemented in the driver. The driver queries the system tables in search 
    of a unique index named with the using "{table}_pkey". For Example:
    </p>
    <pre>
    create table foo (
        id integer primary key,
        data varchar(20)
    );
    </pre>


    <h2>5) Borland Applications</h2>

    <h3><a name="5.1">5.1</a>) What driver/datasource options work well with Borland products?</h3>
    <p>
    Consider setting the following advanced driver options if using Borland:
    </p>
    <ul>
      <li>Check Text as LongVarchar</li>
      <li>Uncheck Unknowns as LongVarchar</li>
      <li>Parse Statements option: Enable it, if using a protocol earlier than PostgreSQL 6.4</li>
      <li>Unknown Sizes Options: Set to "Longest"</li>
    </ul>

    <h3><a name="5.1">5.1</a>) Why do varchar/char datatypes not appear with the correct precision in Borland DBExplorer -OR- why do all varchar/char precisions appear as 128?</h3>
    <p>
    When using the 6.4 protocol, this problem should not be an issue.
    </p>
    <p>
    Prior to the PostgreSQL 6.4 protocol, the backend did not return the size of 
    varchar/char datatypes in a query result and Borland relies heavily on this 
    for both simple queries and the data dictionary import. Therefore, there are 
    several driver options that were developed to help out with this.
    </p>
    <ul>
      <li>Parse Statements option -- driver parses the SQL statement and retrieves 
      characteristics such as precision, nullability, aliases, etc. for the columns.</li>
      <li>Unknown Sizes option -- "longest" will return the precision based on the 
      longest data of all the rows in the result set.</li>
    </ul>
    <p>
    Currently, if the parse statements option is enabled, the parser will fallback 
    on executing the statement if it cannot deal with a particular column. Therefore, 
    it is a good idea to set the unknown sizes to "longest" as well.
    </p>
    
    
    <h2>6) Microsoft Applications</h2>
    
    <h3><a name="6.1">6.1</a>) Why don't int4 based aggregates seem to work?</h3>
    <p>
    Some Aggregates such as sum(int4) and avg(int4) return results using the numeric 
    datatype. This is perfectly legal according to the SQL spec and is done to prevent 
    overflows and other problems, but unfortunately Microsoft's ActiveX Data Objects don't 
    seem to like it. There are two workarounds:
    </p>
    <ul>
      <li>Cast the result to an int4 e.g. SELECT avg(fieldname)::int4 FROM tablename</li>
      <li>Set the ADO CursorLocation to AdUseClient. Note: This will produce a read only recordset.</li>
    </ul>
    
    <h3><a name="6.2">6.2</a>) Why does Access force me specify the Data Source each time I run my SQL Pass-Thru query?</h3>
    <p>
    There is a way to specify a Data Source in the query properties so it doesn't ask you 
    each time. Under the view menu, select properties. For the "ODBC Connect Str" property 
    right after "ODBC;" add "DSN=&lt;your_datasource_name_here&gt;". You can also add other 
    properties if you like such as "ODBC;DSN=my_dsn;UID=me;PWD=test".
    </p>

    <h3><a name="6.3">6.3</a>) Why does MS Access sometimes complain about a GROUP BY or ORDER BY not being in the target list?</h3>
    <p>
    This message comes from the PostgreSQL backend. PostgreSQL currently requires fields 
    in the ORDER BY and GROUP BY clauses to be included in the target list. However, 
    this restriction has been lifted in PostgreSQL 6.4+
    </p>
    <p>
    Older versions of the Microsoft Jet Database Engine, that Access is built on, has 
    some problems that can cause this to occur. Access will insist on throwing in an 
    order by clause in a join query, even if you are not sorting on anything. Even with 
    PostgreSQL 6.4+, the query may no longer error out, BUT it would be sorted in a way 
    you may not want, and there would be no way to change it. To fix this problem, you 
    need to update the Jet database engine to version 3.51. It is available at no charge 
    from Microsoft. Click <a href="http://www.microsoft.com/data">here to download</a> 
    the latest Jet Engine from the Microsoft support site.
    </p>
    
    <h3><a name="6.4">6.4</a>) Why do I get 'Write Conflict - This record has been changed by another user since you started editing it' in Access 2000 and above?</h3>
    <p>
    <b>Contributed by Michael Zedeler (michael.zedeler@@tirush.dk)</b>
    </p>
    <p>
    If you get the following message: "Write Conflict - This record has been changed by 
    another user since you started editing it. [...]" from Access 2000, its likely to be 
    a problem that arises from differing standards between Access and PostgreSQL.
    </p>
    <p>
    From old times, according to some SQL standard, an empty space is by definition equal 
    to NULL. This disposition has caused many grievances over the years, so PostgreSQL rectifies 
    this by deviating from the standard. In PostgreSQL, NULL is NULL and the empty string is the 
    empty string.
    </p>
    <p>
    So when Access retrieves a row from PostgreSQL with fields containing the empty string, it 
    automatically translates them into NULL values. When you try updating this row, the query sent 
    from Access 2000 to PostgreSQL will fail to update the row. An example:
    </p>
    <p>
    You have inserted the following row into table a:
    </p>
    <pre>
        id  | name----+-------------------------  1 | <- contains the empty string. Not NULL.
    </pre>
    <p>
    And then you retrieve the row using Access 2000, subsequently inserting the value "Smartypants" 
    in the "name" field.
    </p>
    <p>
    You would expect Access 2000 to send the following query to PostgreSQL:
    </p>
    <code>
    UPDATE a SET name = 'Smartypants' WHERE id = 1 AND name = ''
    </code>
    <p>
    (The extra "AND name = ''" is included to avoid updates in case that some other user has 
    already updated the given row.)
    </p>
    <p>
    But what Access 2000 actually sends is:
    </p>
    <code>
    UPDATE a SET name = 'Smartypants' WHERE id = 1 AND name IS NULL
    </code>
    <p>
    That query fails because NULL is not being treated as the empty string by PostgreSQL.
    </p>
    <p>
    <b>How to fix the problem</b>
    </p>
    <p>
    I haven't found any way around it, but to stop using empty strings in character fields.
    </p>
    <p>
    The problem only arises when other systems inserts data into PostgreSQL tables, so 
    you'll have to make those systems start using NULL in stead of the empty string, where 
    necessary. When Access 2000 inserts data, it will always translate the empty string into 
    NULL, thus maintaining data that are consistent with the (old?) SQL standard.
    </p>
    <p>
    PostgreSQL 7.2 and above can cause similar problems but for different reasons:
    </p>
    <p>
    <b>Contributed by Sam Hokin (sam@@ims.net)</b>
    </p>
    <p>
    The new PostgreSQL timestamp data type defaults to microsecond 
    precision.  This means that timestamp values are stored like 2002-05-22 
    09:00:00.123456-05.  However, Access does not support the extra precision, 
    so the value that Access uses is 2002-05-22 09:00:00-05.  When one tries to 
    update a record, one gets the error message above because the value that 
    Access uses in its UPDATE query does not match the value in the PostgreSQL 
    table, similar to the NULL vs. empty string conflict that is already 
    reported in this FAQ entry.
    </p>
    <p>
    <b>How to fix the problem</b>
    </p>
    <p>
    The simple fix is to use timestamp(0) rather than timestamp.  Otherwise, 
    one must make sure that all timestamp values entered into the PostgreSQL 
    table have zero fractional second value.
    </p>
    <p>
    Incidentally, this problem occurs in Access 97 as well as Access 2000.
    </p>
    <p>
    <b>Contributed by Steven Citron-Pousty (Steven.Citron-Pousty@@yale.edu)</b>
    </p>
    <p>
    Another way around the issue noted here in access2k and 7.2 is to use a 
    query behind your data view that excludes the timestamp columns. In our 
    case the timestamps are autogenerated so we don't even need to 
    see them. So if you don't need to edit the timestamp value hide the 
    column by making a query without the data value.
    </p>
    
    <h3><a name="6.5">6.5</a>) With MS Access, why can't I index on text fields -OR- why do I get "Invalid field definition 'field'" in definition of index or relationship?</h3>
    <p>
    Text fields are mapped to SQL_LONGVARCHAR by default. As a result MS Access 
    treats these colomns as "Memo" types. The good news is that you can store up 
    to the PostgreSQL block size limit in a text column. PostgreSQL has a tuple 
    limit of just under 8k prior to version 7.1 which includes a new feature 
    called TOAST which allows the storage of much larger strings.
    </p>
    <p>
    You can change the mapping of Text fields to SQL_VARCHAR by unchecking the 
    Advanced driver option "Text as LongVarchar" under Data Type Options. This 
    should allow text fields to be used but you will be limited to the maximum 
    size of a varchar.
    </p>
    
    <h3><a name="6.6">6.6</a>) With MS Access, why can't I GROUP BY,  ORDER BY, or even select WHERE, on columns which are of type "text"?</h3>
    <p>
    Text fields are mapped to SQL_LONGVARCHAR by default. As a result MS Access 
    treats these colomns as "Memo" types. The good news is that you can store up 
    to the PostgreSQL block size limit in a text column. PostgreSQL has a tuple 
    limit of just under 8k prior to version 7.1 which includes a new feature 
    called TOAST which allows the storage of much larger strings.
    </p>
    <p>
    You can change the mapping of Text fields to SQL_VARCHAR by unchecking the 
    Advanced driver option "Text as LongVarchar" under Data Type Options. This 
    should allow text fields to be used.
    </p>
    
    <h3><a name="6.7">6.7</a>) With MS Access, why do I see #Deleted# in rows after some operations?</h3>
    <p>
    This commonly occurs if you have used numeric or int8 (bigint) columns as your 
    primary key. In Access, an Int is a 16 bit value and a Long Int is a 32 bit value,
    unlike PostgreSQL in which an int is a 32 bit value and a bigint is 64 bit. Access
    sees the int8/numeric key as a floating point value, which it cannot use as a key.
    To resolve the problem, stick to int4 if you need numerical primary keys. For more
    intofmation, please see <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;128809">
    Microsoft KB article #128809</a>.
    </p>

</body>
</head>
@


1.7
log
@Correction of site information.
@
text
@d12 1
a12 1
    <p>Last updated: $Date: 2006/09/15 07:52:38 $</p>
d124 2
a125 1
    For Windows, use the ODBC Administrator in Control Panel. Here you can add, modify, or delete data sources.
@


1.6
log
@Add note about #Deleted# columns in Access, per David Gardner
@
text
@d12 1
a12 1
    <p>Last updated: $Date: 2006/08/31 08:38:20 $</p>
d17 1
a17 1
    "http://gborg.postgresql.org/cgi-bin/cvsweb.cgi/~checkout~/psqlodbc/docs/faq.html?content-type=text%2Fhtml;cvsroot=psqlodbc">http://gborg.postgresql.org/cgi-bin/cvsweb.cgi/~checkout~/psqlodbc/docs/faq.html?content-type=text%2Fhtml;cvsroot=psqlodbc</a>.</p>
@


1.5
log
@Prep for 08.02.0100 release
@
text
@d12 1
a12 1
    <p>Last updated: $Date: 2006/04/28 07:51:13 $</p>
d61 1
d573 1
a573 1
    </p
d575 11
@


1.4
log
@FAQ update
@
text
@d12 1
a12 1
    <p>Last updated: $Date: 2005/10/11 07:47:11 $</p>
d34 1
d149 17
@


1.3
log
@Fix spelling of PostgreSQL.
@
text
@d1 557
a557 576
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>psqlODBC FAQ</title>
  </head>

  <body bgcolor="#ffffff" text="#000000" link="#ff0000" vlink="#a00000" alink="#0000ff">
  
    <h1>psqlODBC FAQ</h1>

    <p>Last updated: $Date: 2005/09/06 15:19:13 $</p>

    <P>Current maintainer: Dave Page (<a href="mailto:dpage@@postgresql.org">dpage@@postgresql.org</a>)</p>

    <p>The most recent version of this document can be viewed at <a href=
    "http://gborg.postgresql.org/cgi-bin/cvsweb.cgi/~checkout~/psqlodbc/docs/faq.html?content-type=text%2Fhtml;cvsroot=psqlodbc">http://gborg.postgresql.org/cgi-bin/cvsweb.cgi/~checkout~/psqlodbc/docs/faq.html?content-type=text%2Fhtml;cvsroot=psqlodbc</a>.</p>

    <hr>

    <h2>1) General</h2>
    <a href="#1.1">1.1</a>) How do I submit an idea for a new feature or even a patch?<br>
    <a href="#1.2">1.2</a>) Do I even need to compile the driver to use it?<br>
    <a href="#1.3">1.3</a>) How do I install the driver?<br>
    <a href="#1.4">1.4</a>) What operating systems will the driver run on?<br>
    <a href="#1.5">1.5</a>) I've seen other PostgreSQL ODBC drivers out there. Which one is the right one?<br>
    <a href="#1.6">1.6</a>) How do I report a bug or other problems?<br>
    
    <h2>2) Basics</h2>
    <a href="#2.1">2.1</a>) How do I setup a datasource?<br>
    <a href="#2.2">2.2</a>) What's the difference between a File DSN, System DSN, and User DSN?<br>
    <a href="#2.3">2.3</a>) How do I access more advanced driver and/or datasource options?<br>
    <a href="#2.4">2.4</a>) Where can I discover more information about ODBC errors?<br>
    <a href="#2.5">2.5</a>) There are 2 drivers installed - which should I use?<br>

    <h2>3) Connections</h2>
    <a href="#3.1">3.1</a>) Why do I get a message like "Failed to authenticate client as Postgres user using unknown authentication type:be_recvauth: unrecognized message type: 65536" when I try to connect to a datasource?<br>
    <a href="#3.2">3.2</a>) Why do I get a message like "User authentication failed"?<br>
    <a href="#3.3">3.3</a>) What do I need to do to establish a connection to a database?<br>
    <a href="#3.4">3.4</a>) Does psqlODBC support encrypted login for connections?<br>
    
    <h2>4) Advanced</h2>
    <a href="#4.1">4.1</a>) Why do characters with umlauts or accents, or other non-ASCII characters show up in some applications as '?'<br>
    <a href="#4.2">4.2</a>) What data types does the driver support?<br>
    <a href="#4.3">4.3</a>) How do I use the row versioning -OR- why do I get a message about no operator for xid and int4?<br>
    <a href="#4.4">4.4</a>) Can I use large objects or OLE?<br>
    <a href="#4.5">4.5</a>) Why does the PostgreSQL backend complain about running out of memory when some I browse tables with primary keys?<br>
    <a href="#4.6">4.6</a>) How do I get my application to recognize primary keys?<br>
        
    <h2>5) Borland Applications</h2>
    <a href="#5.1">5.1</a>) What driver/datasource options work well with Borland products?<br>
    <a href="#5.2">5.2</a>) # Why do varchar/char datatypes not appear with the correct precision in Borland DBExplorer -OR- why do all varchar/char precisions appear as 128?<br>    
    
    <h2>6) Microsoft Applications</h2>
    <a href="#6.1">6.1</a>) Why don't int4 based aggregates seem to work?<br>
    <a href="#6.2">6.2</a>) Why does Access force me specify the Data Source each time I run my SQL Pass-Thru query?<br>
    <a href="#6.3">6.3</a>) Why does MS Access sometimes complain about a GROUP BY or ORDER BY not being in the target list?<br>
    <a href="#6.4">6.4</a>) Why do I get 'Write Conflict - This record has been changed by another user since you started editing it' in Access 2000 and above?<br>
    <a href="#6.5">6.5</a>) With MS Access, why can't I index on text fields -OR- why do I get "Invalid field definition 'field'" in definition of index or relationship?<br>
    <a href="#6.6">6.6</a>) With MS Access, why can't I GROUP BY,  ORDER BY, or even select WHERE, on columns which are of type "text"?<br>


    <h2>1) General</h2>
 
    <h3><a name="1.1">1.1</a>) How do I submit an idea for a new feature or even a patch?</h3>
    <p>
    You can send mail to <a href="pgsql-odbc@@postgresql.org">pgsql-odbc@@postgresql.org</a>.
    </p>

    <h3><a name="1.2">1.2</a>) Do I even need to compile the driver to use it?</h3>
    <p>
    Probably not. If you are using Windows, all you really need to do is download and run 
    the Full distribution.
    </p>

    <h3><a name="1.3">1.3</a>) How do I install the driver?</h3>
    <p>
    The easiest way to install the driver is to get the Full distribution. Just download, 
    unzip and run the setup program program. The installation is a standard Windows 
    Installer package that will guide you through the process. For future upgrades, 
    the MSI distribution can be used. This is considerably smaller as it does not 
    include the Windows Installer redistributable which you only need install once. 
    The second option is to compile the driver yourself. If you are using this 
    driver on a unix platform, this is currently your only option.
    </p>
    
    <h3><a name="1.4">1.4</a>) What operating systems will the driver run on?</h3>
    <p>
    The psqlODBC executable is written and compiled to run on 32 bit Wintel platform. 
    This includes Windows 95, 98, ME, NT, 2000 and XP. 16 bit applications are capable 
    of using the 32 bit driver but only on these platforms.
    </p>
    <p>
    We do not distribute binaries for Unix. The source code, however has been ported 
    to compile under Unix. There are two driver managers available for Unix, 
    <a href="http://www.unixodbc.org/">UnixODBC</a> and <a href="http://www.iodbc.org/">iODBC</a>.
    </p>
    
    <h3><a name="1.5">1.5</a>) I've seen other PostgreSQL ODBC drivers out there. Which one is the right one?</h3>
    <p>
    This one! This is <i>the</i> official PostgreSQL ODBC driver.
    </p>
    
    <h3><a name="1.6">1.6</a>) How do I report a bug or other problems?</h3>
    <p>
    You can send mail to pgsql-odbc@@postgresql.org When you do, however, you should attach the following:
    </p>
    <ul>
      <li>your ODBC driver version</li>
      <li>your PostgreSQL database version</li>
      <li>any error messages you saw on the screen</li>
      <li>the debug log (mylog_????.log) file (you will have to enable the mylog driver option)</li>
    </ul>
    <p>
    Before posting however, please ensure you are running the latest version of psqlODBC.
    </p>
    
    
    <h2>2) Basics</h2>

    <h3><a name="2.1">2.1</a>) How do I setup a datasource?</h3>
    <p>
    For Windows, use the ODBC Administrator in Control Panel. Here you can add, modify, or delete data sources.
    </p>

    <h3><a name="2.2">2.2</a>) What's the difference between a File DSN, System DSN, and User DSN?</h3>
    <p>
    System DSN's and User DSN's differ only in who can access them on the system. 
    A File DSN, however, is not really a datasource. It is a file that contains all 
    the connection parameters used to connect directly to an ODBC driver.
    </p>
    
    <h3><a name="2.3">2.3</a>) How do I access more advanced driver and/or datasource options?</h3>
    <p>
    First, select your favorite datasource to configure. Then in the "PostgreSQL Driver Setup" dialog, 
    select under "Options (Advanced)" either the Driver button or Datasource button. This will bring 
    up another dialog box which contains options you can configure. Refer to the Configuration Help for
    information on all these options.
    </p>
    
    <h3><a name="2.4">2.4</a>) Where can I discover more information about ODBC errors?</h3>
    <p>
    The ODBC driver has an option to log all direct communication (queries, updates, etc.) with 
    the backend as well as error messages and notices in the commlog file. In addition, it now 
    also logs any ODBC connection and statement errors in this file with detailed information. 
    This is good for applications that give misleading, little, or no descriptive information 
    when something goes wrong (VisData is a good example).
    </p>

    <h3><a name="2.5">2.5</a>) There are 2 drivers installed - which should I use?</h3>
    <p>
    <b>PostgreSQL Unicode</b> is a Unicode enabled driver that will work well with modern versions of
    applications such as Microsoft Access, with character from a huge range of languages. You should
    use this driver with PostgreSQL databases encoded as 'UNICODE' (more precisely known as 'UTF-8' in
    PostgreSQL).
    </p>
    <p>
    <b>PostgreSQL ANSI</b> is an ANSI driver which is also able to handle some multibyte character sets
    such as EUC_JP, BIG5 and Shift-JIS. This driver should also be used with databases encoded using
    any of the LATIN charactersets.
    </p>
    <p>
    Note that some applications (notably Borland BDE) do not work properly with Unicode ODBC drivers.
    In this case, you must use the ANSI driver.
    </p>
    

    <h2>3) Connections</h2>
    
    <h3><a name="3.1">3.1</a>) Why do I get a message like "Failed to authenticate client as Postgres user using unknown authentication type:be_recvauth: unrecognized message type: 65536" when I try to connect to a datasource?</h3>
    <p>
    This message comes from the PostgreSQL backend, most likely when there is a protocol 
    mismatch between the ODBC driver and the backend. For example, if you are using PostgreSQL
    6.2 as the backend and try to use the ODBC driver without correctly setting the protocol, 
    this error will occur. You must check the "6.2 protocol" advanced datasource option in 
    the ODBC driver configuration dialog.
    </p>
    <p>
    <b>Note:</b> If you're still running 6.x these days, you really, really, really should upgrade to 8.x as soon as possible!!
    </p>

    <h3><a name="3.2">3.2</a>) Why do I get a message like "User authentication failed"?</h3>
    <p>
    Verify that the database you are trying to connect to exists and is accessible by you. 
    Also, see the above question in regards to user name and password authentication.
    </p>

    <h3><a name="3.3">3.3</a>) What do I need to do to establish a connection to a database?</h3>
    <p>
    ODBC Connection Checklist:
    </p>

    <ul>
      <li>ODBC Driver Data Source Checks
        <ul>
          <li>Valid and resolvable hostname.</li>
          <li>Valid port number (default is 5432).</li>
          <li>Valid and existing database name.</li>
          <li>Valid user name.</li>
          <li>Valid password for the specified user (required if pg_hba.config is set to password authenticate your client).</li>
        </ul>
      <br>&nbsp;</li>

      <li>PostgreSQL Server Checks
        <ul>
          <li>Postmaster must be running.</li>
          <li>Postmaster must run with the -i option , or tcpip=true in postgresql.conf to allow remote connections.</li>
          <li>The pg_hba.conf file in /data directory must be configured to allow your remote host to connect.</li>
        </ul>
      </li>
    </ul>
    
    <h3><a name="3.4">3.4</a>) Does psqlODBC support encrypted login for connections?</h3>
    <p>
    Yes. psqlODBC supports "md5" encrypted logins, but not "crypt" logins. Keep 
    in mind that after login, ODBC sends all queries in plain text, so all you're 
    protecting is your password. Also, support for md5 logins was added in late 2001, 
    so if you have an older version of psqlODBC you may need to update it.
    </p>
    <p>
    <b>Note:</b> As of version 08.01.002, psqlODBC now supports SSL encrypted connections.
    </p>

    <h2>4) Advanced</h2>

    <h3><a name="4.1">4.1</a>) Why do characters with umlauts or accents, or other non-ASCII characters show up in some applications as '?'</h3>
    <p>
    You are probably using the <b>PostgreSQL Unicode</b> driver with non-Unicode,
    8 bit data - for example, from one of the LATIN encodings. You should either 
    use the <b>PostgreSQL ANSI</b> driver, or move your data to a Unicode database.
    </p>
    
    <h3><a name="4.2">4.2</a>) What data types does the driver support?</h3>
    <p>
    The driver provides full support for all PostgreSQL standard data types. 
    These are: bool, int2, int4, int8, float4, float8, date, time, abstime, 
    datetime, timestamp, char, varchar, and text.
    </p>
    <p>
    There is partial support for all other data types. Examples of these: 
    point, circle, box and arrays. String support only is provided for these 
    non-standard types. In other words, they are returned as SQL_VARCHAR and 
    can be displayed and updated like any other data type. The resulting 
    behavior will probably vary some with each application and data type.
    </p>
    <p>
    In the case of int4[] and MS Access 97 it does an effective job. The array 
    can be displayed and updated cleanly. Arithmetic is a little tricky. MS Access 
    complains about "t.a[1]" in the query builder. It does not like the syntax and 
    never sends it to the backend. The work around is to choose the SQL Pass-thru 
    option. This will allow you to build expressions like "t.a[0] * t.a[1]". The 
    hassle is that every time you run the query in Access 97 it prompts you with 
    a database connection dialog.
    </p>
    <p>
    MS Excel in combination w/ MS Query may provide a better solution. It passes 
    every query through. I try to stay away from the more exotic types if I know I 
    am going to expose them to the public.
    </p>
    
    <h3><a name="4.3">4.3</a>) How do I use the row versioning -OR- why do I get a message about no operator for xid and int4?</h3>
    <p>
    Some of the operators are missing in some releases of PostgreSQL (anyone remember 
    which?) so in order to use row versioning, you must overload the int4eq function 
    for use with the xid type. Also, you need to create an operator to compare xid to 
    int4. You must do this for each database you want to use this feature on. This will 
    probably not be necessary in PostgreSQL 6.4 since it will be added. Here are the details:
    </p>
    <pre>
    create function int4eq(xid,int4)
        returns bool
        as ''
        language 'internal';

    create operator = (
        leftarg=xid,
        rightarg=int4,
        procedure=int4eq,
        commutator='=',
        negator='<>',
        restrict=eqsel,
        join=eqjoinsel
    );
    </pre>
    
    <h3><a name="4.4">4.4</a>) Can I use large objects or OLE?</h3>
    <p>
    Large objects are mapped to LONGVARBINARY in the driver to allow storing things like OLE 
    objects in Microsoft Access. Multiple SQLPutData and SQLGetData calls are usually used to 
    send and retrieve these objects. The driver creates a new large object and simply inserts 
    its 'identifier' into the respective table. However, since PostgreSQL uses an 'Oid' to identify 
    a Large Object, it is necessary to create a new PostgreSQL type to be able to discriminate 
    between an ordinary Oid and a Large Object Oid. Until this new type becomes an official 
    part of PostgreSQL, it must be added into the desired database and looked up for each connection. 
    The type used in the driver is simply called "lo" and here is the command used to create it:
    </p>
    <pre>
    create type lo (
        internallength=4,
        externallength=10,
        input=int4in,
        output=int4out,
        default='',
        passedbyvalue
    );

    create table employee (
        id integer,
        name varchar(30),
        picture lo
    );
    </pre>
    <p>
    Once this is done, simply use the new 'lo' type to define columns in that database. When the driver 
    sees an 'lo' type, it will handle it as SQL_LONGVARBINARY.
    </p>
    <p>
    Another important note is that this new type is lacking in functionality. It will not cleanup after 
    itself on updates and deletes, thus leaving orphans around and using up extra disk space. And 
    currently, PostgreSQL does not support the vacuuming of large objects.
    </p>
    <p>
    It would not be too difficult to write a interim stand-alone cleanup process to run at some interval 
    on the server. It is only a matter of searching pg_attribute for lo data type columns and building 
    a list of lo's by querying each table that contains lo's. Then compare this list with with the xinv.* 
    in pg_class. The xinv.* with out a pointer are orphans and should be dropped.
    </p>
    <p>
    Hopefully in the future, a real large object data type will be available as a base type. But for now, 
    it sure is fun to stick a Word document, Visio document, or AVI of a dancing baby into a database 
    column, even if you will fill up your server's hard disk after a while!
    </p>
    
    <h3><a name="4.5">4.5</a>) Why does the PostgreSQL backend complain about running out of memory when some I browse tables with primary keys?</h3>
    <p>
    The Jet Database Engine (used by Access) and others can use "keysets" to access records. Depending 
    on how many parts are in the key, performance can range from slow to crashing of the backend. Here 
    is a keyset query using 10 rows (the typical keyset amount):
    </p>
    <pre>
    -- This is a 3 part key

    select ... from foo where
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 1
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 2
    ...
        (v1 = "?" AND v2 = "?" AND v3 ="?") OR -- line 9
        (v1 = "?" AND v2 = "?" AND v3 ="?")    -- line 10
    </pre>
    <p>
    The question marks are replaced with the key values
    </p>
    <p>
    Prior to PostgreSQL 6.4, this was a major problem. But there are at least 2 fixes in place for this as 
    of 6.4. One of the fixes is called KSQO (Keyset Query Optimization). As of 6.4, the driver now turns 
    this on by default, although this can be changed in the Advanced Driver options settings.
    </p>
    
    <h3><a name="4.6">4.6</a>) How do I get my application to recognize primary keys?</h3>
    <p>
    SQLPrimaryKeys() is implemented in the driver. The driver queries the system tables in search 
    of a unique index named with the using "{table}_pkey". For Example:
    </p>
    <pre>
    create table foo (
        id integer primary key,
        data varchar(20)
    );
    </pre>


    <h2>5) Borland Applications</h2>

    <h3><a name="5.1">5.1</a>) What driver/datasource options work well with Borland products?</h3>
    <p>
    Consider setting the following advanced driver options if using Borland:
    </p>
    <ul>
      <li>Check Text as LongVarchar</li>
      <li>Uncheck Unknowns as LongVarchar</li>
      <li>Parse Statements option: Enable it, if using a protocol earlier than PostgreSQL 6.4</li>
      <li>Unknown Sizes Options: Set to "Longest"</li>
    </ul>

    <h3><a name="5.1">5.1</a>) Why do varchar/char datatypes not appear with the correct precision in Borland DBExplorer -OR- why do all varchar/char precisions appear as 128?</h3>
    <p>
    When using the 6.4 protocol, this problem should not be an issue.
    </p>
    <p>
    Prior to the PostgreSQL 6.4 protocol, the backend did not return the size of 
    varchar/char datatypes in a query result and Borland relies heavily on this 
    for both simple queries and the data dictionary import. Therefore, there are 
    several driver options that were developed to help out with this.
    </p>
    <ul>
      <li>Parse Statements option -- driver parses the SQL statement and retrieves 
      characteristics such as precision, nullability, aliases, etc. for the columns.</li>
      <li>Unknown Sizes option -- "longest" will return the precision based on the 
      longest data of all the rows in the result set.</li>
    </ul>
    <p>
    Currently, if the parse statements option is enabled, the parser will fallback 
    on executing the statement if it cannot deal with a particular column. Therefore, 
    it is a good idea to set the unknown sizes to "longest" as well.
    </p>
    
    
    <h2>6) Microsoft Applications</h2>
    
    <h3><a name="6.1">6.1</a>) Why don't int4 based aggregates seem to work?</h3>
    <p>
    Some Aggregates such as sum(int4) and avg(int4) return results using the numeric 
    datatype. This is perfectly legal according to the SQL spec and is done to prevent 
    overflows and other problems, but unfortunately Microsoft's ActiveX Data Objects don't 
    seem to like it. There are two workarounds:
    </p>
    <ul>
      <li>Cast the result to an int4 e.g. SELECT avg(fieldname)::int4 FROM tablename</li>
      <li>Set the ADO CursorLocation to AdUseClient. Note: This will produce a read only recordset.</li>
    </ul>
    
    <h3><a name="6.2">6.2</a>) Why does Access force me specify the Data Source each time I run my SQL Pass-Thru query?</h3>
    <p>
    There is a way to specify a Data Source in the query properties so it doesn't ask you 
    each time. Under the view menu, select properties. For the "ODBC Connect Str" property 
    right after "ODBC;" add "DSN=&lt;your_datasource_name_here&gt;". You can also add other 
    properties if you like such as "ODBC;DSN=my_dsn;UID=me;PWD=test".
    </p>

    <h3><a name="6.3">6.3</a>) Why does MS Access sometimes complain about a GROUP BY or ORDER BY not being in the target list?</h3>
    <p>
    This message comes from the PostgreSQL backend. PostgreSQL currently requires fields 
    in the ORDER BY and GROUP BY clauses to be included in the target list. However, 
    this restriction has been lifted in PostgreSQL 6.4+
    </p>
    <p>
    Older versions of the Microsoft Jet Database Engine, that Access is built on, has 
    some problems that can cause this to occur. Access will insist on throwing in an 
    order by clause in a join query, even if you are not sorting on anything. Even with 
    PostgreSQL 6.4+, the query may no longer error out, BUT it would be sorted in a way 
    you may not want, and there would be no way to change it. To fix this problem, you 
    need to update the Jet database engine to version 3.51. It is available at no charge 
    from Microsoft. Click <a href="http://www.microsoft.com/data">here to download</a> 
    the latest Jet Engine from the Microsoft support site.
    </p>
    
    <h3><a name="6.4">6.4</a>) Why do I get 'Write Conflict - This record has been changed by another user since you started editing it' in Access 2000 and above?</h3>
    <p>
    <b>Contributed by Michael Zedeler (michael.zedeler@@tirush.dk)</b>
    </p>
    <p>
    If you get the following message: "Write Conflict - This record has been changed by 
    another user since you started editing it. [...]" from Access 2000, its likely to be 
    a problem that arises from differing standards between Access and PostgreSQL.
    </p>
    <p>
    From old times, according to some SQL standard, an empty space is by definition equal 
    to NULL. This disposition has caused many grievances over the years, so PostgreSQL rectifies 
    this by deviating from the standard. In PostgreSQL, NULL is NULL and the empty string is the 
    empty string.
    </p>
    <p>
    So when Access retrieves a row from PostgreSQL with fields containing the empty string, it 
    automatically translates them into NULL values. When you try updating this row, the query sent 
    from Access 2000 to PostgreSQL will fail to update the row. An example:
    </p>
    <p>
    You have inserted the following row into table a:
    </p>
    <pre>
        id  | name----+-------------------------  1 | <- contains the empty string. Not NULL.
    </pre>
    <p>
    And then you retrieve the row using Access 2000, subsequently inserting the value "Smartypants" 
    in the "name" field.
    </p>
    <p>
    You would expect Access 2000 to send the following query to PostgreSQL:
    </p>
    <code>
    UPDATE a SET name = 'Smartypants' WHERE id = 1 AND name = ''
    </code>
    <p>
    (The extra "AND name = ''" is included to avoid updates in case that some other user has 
    already updated the given row.)
    </p>
    <p>
    But what Access 2000 actually sends is:
    </p>
    <code>
    UPDATE a SET name = 'Smartypants' WHERE id = 1 AND name IS NULL
    </code>
    <p>
    That query fails because NULL is not being treated as the empty string by PostgreSQL.
    </p>
    <p>
    <b>How to fix the problem</b>
    </p>
    <p>
    I haven't found any way around it, but to stop using empty strings in character fields.
    </p>
    <p>
    The problem only arises when other systems inserts data into PostgreSQL tables, so 
    you'll have to make those systems start using NULL in stead of the empty string, where 
    necessary. When Access 2000 inserts data, it will always translate the empty string into 
    NULL, thus maintaining data that are consistent with the (old?) SQL standard.
    </p>
    <p>
    PostgreSQL 7.2 and above can cause similar problems but for different reasons:
    </p>
    <p>
    <b>Contributed by Sam Hokin (sam@@ims.net)</b>
    </p>
    <p>
    The new PostgreSQL timestamp data type defaults to microsecond 
    precision.  This means that timestamp values are stored like 2002-05-22 
    09:00:00.123456-05.  However, Access does not support the extra precision, 
    so the value that Access uses is 2002-05-22 09:00:00-05.  When one tries to 
    update a record, one gets the error message above because the value that 
    Access uses in its UPDATE query does not match the value in the PostgreSQL 
    table, similar to the NULL vs. empty string conflict that is already 
    reported in this FAQ entry.
    </p>
    <p>
    <b>How to fix the problem</b>
    </p>
    <p>
    The simple fix is to use timestamp(0) rather than timestamp.  Otherwise, 
    one must make sure that all timestamp values entered into the PostgreSQL 
    table have zero fractional second value.
    </p>
    <p>
    Incidentally, this problem occurs in Access 97 as well as Access 2000.
    </p>
    <p>
    <b>Contributed by Steven Citron-Pousty (Steven.Citron-Pousty@@yale.edu)</b>
    </p>
    <p>
    Another way around the issue noted here in access2k and 7.2 is to use a 
    query behind your data view that excludes the timestamp columns. In our 
    case the timestamps are autogenerated so we don't even need to 
    see them. So if you don't need to edit the timestamp value hide the 
    column by making a query without the data value.
    </p>
    
    <h3><a name="6.5">6.5</a>) With MS Access, why can't I index on text fields -OR- why do I get "Invalid field definition 'field'" in definition of index or relationship?</h3>
    <p>
    Text fields are mapped to SQL_LONGVARCHAR by default. As a result MS Access 
    treats these colomns as "Memo" types. The good news is that you can store up 
    to the PostgreSQL block size limit in a text column. PostgreSQL has a tuple 
    limit of just under 8k prior to version 7.1 which includes a new feature 
    called TOAST which allows the storage of much larger strings.
    </p>
    <p>
    You can change the mapping of Text fields to SQL_VARCHAR by unchecking the 
    Advanced driver option "Text as LongVarchar" under Data Type Options. This 
    should allow text fields to be used but you will be limited to the maximum 
    size of a varchar.
    </p>
    
    <h3><a name="6.6">6.6</a>) With MS Access, why can't I GROUP BY,  ORDER BY, or even select WHERE, on columns which are of type "text"?</h3>
    <p>
    Text fields are mapped to SQL_LONGVARCHAR by default. As a result MS Access 
    treats these colomns as "Memo" types. The good news is that you can store up 
    to the PostgreSQL block size limit in a text column. PostgreSQL has a tuple 
    limit of just under 8k prior to version 7.1 which includes a new feature 
    called TOAST which allows the storage of much larger strings.
    </p>
    <p>
    You can change the mapping of Text fields to SQL_VARCHAR by unchecking the 
    Advanced driver option "Text as LongVarchar" under Data Type Options. This 
    should allow text fields to be used.
    </p
    
</body>
</head>
@


1.2
log
@Explain which driver users should choose.
@
text
@d12 1
a12 1
    <p>Last updated: $Date: 2005/09/06 16:22:34 $</p>
d267 1
a267 1
    probably not be necessary in Postgres 6.4 since it will be added. Here are the details:
d291 2
a292 2
    its 'identifier' into the respective table. However, since Postgres uses an 'Oid' to identify 
    a Large Object, it is necessary to create a new Postgres type to be able to discriminate 
d294 1
a294 1
    part of Postgres, it must be added into the desired database and looked up for each connection. 
d320 1
a320 1
    currently, Postgres does not support the vacuuming of large objects.
d354 1
a354 1
    Prior to Postgres 6.4, this was a major problem. But there are at least 2 fixes in place for this as 
d381 1
a381 1
      <li>Parse Statements option: Enable it, if using a protocol earlier than Postgres 6.4</li>
d390 1
a390 1
    Prior to the Postgres 6.4 protocol, the backend did not return the size of 
d432 1
a432 1
    This message comes from the PostgreSQL backend. Postgres currently requires fields 
d463 1
a463 1
    So when Access retrieves a row from PostgreSQl with fields containing the empty string, it 
@


1.1
log
@Add FAQ.
@
text
@d12 1
a12 1
    <p>Last updated: $Date: 2005/08/27 21:22:35 $</p>
d34 1
d149 17
d228 3
a230 4
    You probably chose SQL_ASCII as your database encoding. If you need to use non-7bit ASCII 
    characters, you should use the appropriate encoding for your data. See 
    <a href="http://www.postgresql.org/docs/8.0/interactive/multibyte.html">http://www.postgresql.org/docs/8.0/interactive/multibyte.html<a/>
    for more details.
d576 1
a576 1
</head>@

