title: How to make VARCHAR the preferred type for strings in PostgreSQL?
body: <p>PostgreSQL have the &quot;preferred types&quot; for type categories.
  For strings, the preferred type is TEXT, so if one calls</p>
  <pre><code>SELECT PG_TYPEOF('FOO' || 'BAR');
  </code></pre>
  <p>The result will be <code>TEXT</code>.</p>
  <p>I've already tried to change the <code>pg_type</code> table like this:</p>
  <pre><code>UPDATE PG_CATALOG.PG_TYPE 
     SET TYPISPREFERRED = (UPPER(TYPNAME) = 'VARCHAR')
   WHERE TYPCATEGORY = 'S'
  </code></pre>
  <p>Now the <code>TYPISPREFERRED</code> column for the type TEXT is false and for VARCHAR is true, but <code>SELECT PG_TYPEOF('FOO' || 'BAR');</code> still returns <code>TEXT</code>.</p>
  <p>I need it to return VARCHAR because I'm migrating an old Delphi system from Firebird and there are too much code that use <code>'FOO' || 'BAR'</code> as a TStringField, but with the TEXT type it needs to be a TMemoField, which is totally different.</p>
  <hr />
  <h2>Edit¹:</h2>
  <p>I tried this:</p>
  <pre><code>with(oConnection.FormatOptions)do
  begin
    with MapRules.Add do
    begin
      SizeMax        := 200;
      TypeMask       := 'text';
      TargetDataType := dtWideString;
    end;
  end;
  </code></pre>
  <p>Tried this too</p>
  <pre><code>with(oConnection.FormatOptions)do
  begin
    with MapRules.Add do
    begin
      SizeMax        := 1;            // Tried with -1 and 0 too
      SizeMax        := 200;
      SourceDataType := dtMemo;
      TargetDataType := dtAnsiString;
    end;
  end;
  </code></pre>
  <p>But it doesn't work. I think it gets the size set to the value, not the actual size of it. In PostgreSQL the TEXT type do not need any size to be set, so it always get it as a 0 size and convert all TEXT to String doing a big mess that is not pretty.</p>