diff --git a/Makefile.am b/Makefile.am
index 797bee4..4b06c8d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -93,6 +93,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
 	test/expected/bookmark.out \
 	test/expected/boolsaschar.out \
 	test/expected/catalogfunctions.out \
+	test/expected/colattribute.out \
 	test/expected/commands.out \
 	test/expected/connect.out \
 	test/expected/cte.out \
@@ -135,6 +136,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
 	test/src/bookmark-test.c \
 	test/src/boolsaschar-test.c \
 	test/src/catalogfunctions-test.c \
+	test/src/colattribute-test.c \
 	test/src/commands-test.c \
 	test/src/common.c \
 	test/src/common.h \
diff --git a/pgtypes.c b/pgtypes.c
index 60a94bb..05191ef 100644
--- a/pgtypes.c
+++ b/pgtypes.c
@@ -1198,11 +1198,13 @@ pgtype_attr_transfer_octet_length(const ConnectionClass *conn, OID type, int att
 {
 	int	coef = 1;
 	Int4	maxvarc, column_size;
+
 	switch (type)
 	{
 		case PG_TYPE_VARCHAR:
 		case PG_TYPE_BPCHAR:
 		case PG_TYPE_TEXT:
+		case PG_TYPE_UNKNOWN:
 			column_size = pgtype_attr_column_size(conn, type, atttypmod, PG_UNSPECIFIED, handle_unknown_size_as);
 			if (SQL_NO_TOTAL == column_size)
 				return column_size;
diff --git a/test/expected/colattribute.out b/test/expected/colattribute.out
new file mode 100644
index 0000000..e9661b2
--- /dev/null
+++ b/test/expected/colattribute.out
@@ -0,0 +1,96 @@
+\! "./src/colattribute-test"
+Running tests with UnknownSizes=-1;MaxVarcharSize=100...
+connected
+Testing SQLColAttribute...
+
+-- Column 1: intcol --
+SQL_DESC_OCTET_LENGTH: 0
+
+-- Column 2: textcol --
+SQL_DESC_OCTET_LENGTH: 49140
+
+-- Column 3: unknowncol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 4: varcharcol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 5: empty_varchar_col --
+SQL_DESC_OCTET_LENGTH: 100
+disconnecting
+Running tests with UnknownSizes=0;MaxVarcharSize=100...
+connected
+Testing SQLColAttribute...
+
+-- Column 1: intcol --
+SQL_DESC_OCTET_LENGTH: 0
+
+-- Column 2: textcol --
+SQL_DESC_OCTET_LENGTH: 49140
+
+-- Column 3: unknowncol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 4: varcharcol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 5: empty_varchar_col --
+SQL_DESC_OCTET_LENGTH: 100
+disconnecting
+Running tests with UnknownSizes=1;MaxVarcharSize=100...
+connected
+Testing SQLColAttribute...
+
+-- Column 1: intcol --
+SQL_DESC_OCTET_LENGTH: 0
+
+-- Column 2: textcol --
+SQL_DESC_OCTET_LENGTH: 49140
+
+-- Column 3: unknowncol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 4: varcharcol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 5: empty_varchar_col --
+SQL_DESC_OCTET_LENGTH: 100
+disconnecting
+Running tests with UnknownSizes=2;MaxVarcharSize=100...
+connected
+Testing SQLColAttribute...
+
+-- Column 1: intcol --
+SQL_DESC_OCTET_LENGTH: 0
+
+-- Column 2: textcol --
+SQL_DESC_OCTET_LENGTH: 36
+
+-- Column 3: unknowncol --
+SQL_DESC_OCTET_LENGTH: 84
+
+-- Column 4: varcharcol --
+SQL_DESC_OCTET_LENGTH: 84
+
+-- Column 5: empty_varchar_col --
+SQL_DESC_OCTET_LENGTH: 100
+disconnecting
+Running tests with UnknownSizes=100;MaxVarcharSize=100...
+connected
+Testing SQLColAttribute...
+
+-- Column 1: intcol --
+SQL_DESC_OCTET_LENGTH: 0
+
+-- Column 2: textcol --
+SQL_DESC_OCTET_LENGTH: 49140
+
+-- Column 3: unknowncol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 4: varcharcol --
+SQL_DESC_OCTET_LENGTH: 100
+
+-- Column 5: empty_varchar_col --
+SQL_DESC_OCTET_LENGTH: 100
+disconnecting
diff --git a/test/src/colattribute-test.c b/test/src/colattribute-test.c
new file mode 100644
index 0000000..b6ed51d
--- /dev/null
+++ b/test/src/colattribute-test.c
@@ -0,0 +1,70 @@
+/*
+ * Test SQLColAttribute
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+static void
+runtest(char *extra_conn_options)
+{
+	int rc;
+	HSTMT hstmt = SQL_NULL_HSTMT;
+	SQLUSMALLINT i;
+
+	printf("Running tests with %s...\n", extra_conn_options);
+
+	/* The behavior of these tests depend on the UnknownSizes parameter */
+	test_connect_ext(extra_conn_options);
+
+	rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
+	if (!SQL_SUCCEEDED(rc))
+	{
+		print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
+		exit(1);
+	}
+
+	/*
+	 * Get column attributes of a simple query.
+	 */
+	printf("Testing SQLColAttribute...\n");
+	rc = SQLExecDirect(hstmt,
+			(SQLCHAR *) "SELECT '1'::int AS intcol, 'foobar'::text AS textcol, 'unknown string' AS unknowncol, 'varchar string' as varcharcol, '' as empty_varchar_col",
+			SQL_NTS);
+	CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+	for (i = 1 ; i <= 5; i++)
+	{
+		char buffer[64];
+		SQLLEN number;
+
+		rc = SQLColAttribute(hstmt, i, SQL_DESC_LABEL, buffer, 64, NULL, NULL);
+		CHECK_STMT_RESULT(rc, "SQLColAttribute failed", hstmt);
+		printf("\n-- Column %d: %s --\n", i, buffer);
+
+		rc = SQLColAttribute(hstmt, i, SQL_DESC_OCTET_LENGTH, NULL, SQL_IS_INTEGER, NULL, &number);
+		CHECK_STMT_RESULT(rc, "SQLColAttribute failed", hstmt);
+		printf("SQL_DESC_OCTET_LENGTH: %d\n", (int) number);
+	}
+
+	/* Clean up */
+	test_disconnect();
+}
+
+int main(int argc, char **argv)
+{
+
+	/*
+	 * The output of these tests depend on the UnknownSizes and
+	 * MaxVarcharSize parameters
+	 */
+	runtest("UnknownSizes=-1;MaxVarcharSize=100");
+	runtest("UnknownSizes=0;MaxVarcharSize=100");
+	runtest("UnknownSizes=1;MaxVarcharSize=100");
+	runtest("UnknownSizes=2;MaxVarcharSize=100");
+	runtest("UnknownSizes=100;MaxVarcharSize=100");
+
+	return 0;
+}
diff --git a/test/tests b/test/tests
index bf1a2c1..49fcd95 100644
--- a/test/tests
+++ b/test/tests
@@ -14,6 +14,7 @@ TESTBINS = src/connect-test \
 	src/commands-test \
 	src/multistmt-test \
 	src/getresult-test \
+	src/colattribute-test \
 	src/result-conversions-test \
 	src/prepare-test \
 	src/params-test \
