diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 5f27120..ab0e858 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -58,7 +58,7 @@ extern char *filename_completion_function();
 #endif
 
 /* word break characters */
-#define WORD_BREAKS		"\t\n@$><=;|&{() "
+#define WORD_BREAKS		"\t\n@$><=;:|&{() "
 
 /*
  * Since readline doesn't let us pass any state through to the tab completion
@@ -1312,15 +1312,23 @@ psql_completion(const char *text, int start, int end)
 	if (text[0] == '\\')
 		COMPLETE_WITH_LIST_CS(backslash_commands);
 
+	/* If current word is a typecast, handle that case */
+	else if (previous_words_count >= 2 &&
+			 previous_words[1][strlen(previous_words[1])-1] == ':' &&
+			 TailMatches1(":"))
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL);
+
 	/* If current word is a variable interpolation, handle that case */
-	else if (text[0] == ':' && text[1] != ':')
-	{
-		if (text[1] == '\'')
-			matches = complete_from_variables(text, ":'", "'", true);
-		else if (text[1] == '"')
-			matches = complete_from_variables(text, ":\"", "\"", true);
+	else if ((previous_words_count < 2 ||
+			  previous_words[1][strlen(previous_words[1])-1] != ':') &&
+			 TailMatches1(":"))
+	{
+		if (text[0] == '\'')
+			matches = complete_from_variables(text, "'", "'", true);
+		else if (text[0] == '"')
+			matches = complete_from_variables(text, "\"", "\"", true);
 		else
-			matches = complete_from_variables(text, ":", "", true);
+			matches = complete_from_variables(text, "", "", true);
 	}
 
 	/* If no previous word, suggest one of the basic sql commands */
