diff --git a/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/PostgresIntegrationSuite.scala b/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/PostgresIntegrationSuite.scala
index e5141a8911de2..eb1ee516d7aa2 100644
--- a/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/PostgresIntegrationSuite.scala
+++ b/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/PostgresIntegrationSuite.scala
@@ -89,7 +89,10 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationSuite {
.executeUpdate()
conn.prepareStatement("CREATE TABLE st_with_array (c0 uuid, c1 inet, c2 cidr," +
- "c3 json, c4 jsonb, c5 uuid[], c6 inet[], c7 cidr[], c8 json[], c9 jsonb[])")
+ "c3 json, c4 jsonb, c5 uuid[], c6 inet[], c7 cidr[], c8 json[], c9 jsonb[], c10 xml[], " +
+ "c11 tsvector[], c12 tsquery[], c13 macaddr[], c14 txid_snapshot[], c15 point[], " +
+ "c16 line[], c17 lseg[], c18 box[], c19 path[], c20 polygon[], c21 circle[], c22 pg_lsn[], " +
+ "c23 bit varying(6)[], c24 interval[], c25 macaddr8[], c26 pg_snapshot[])")
.executeUpdate()
conn.prepareStatement("INSERT INTO st_with_array VALUES ( " +
"'0a532531-cdf1-45e3-963d-5de90b6a30f1', '172.168.22.1', '192.168.100.128/25', " +
@@ -98,7 +101,24 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationSuite {
"'205f9bfc-018c-4452-a605-609c0cfad228']::uuid[], ARRAY['172.16.0.41', " +
"'172.16.0.42']::inet[], ARRAY['192.168.0.0/24', '10.1.0.0/16']::cidr[], " +
"""ARRAY['{"a": "foo", "b": "bar"}', '{"a": 1, "b": 2}']::json[], """ +
- """ARRAY['{"a": 1, "b": 2, "c": 3}']::jsonb[])"""
+ """ARRAY['{"a": 1, "b": 2, "c": 3}']::jsonb[], """ +
+ """ARRAY['id10']::xml[], ARRAY['The dog laying on the grass', """ +
+ """'the:1 cat:2 is:3 on:4 the:5 table:6']::tsvector[], """ +
+ """ARRAY['programming & language & ! interpreter', 'cat:AB & dog:CD']::tsquery[], """ +
+ """ARRAY['12:34:56:78:90:ab', 'cd-ef-12-34-56-78']::macaddr[], """ +
+ """ARRAY['10:20:10,14,15']::txid_snapshot[], """ +
+ """ARRAY['(800, 600)', '83.24, 5.10']::point[], """ +
+ """ARRAY['(23.8, 56.2), (16.23, 89.2)', '{23.85, 10.87, 5.92}']::line[], """ +
+ """ARRAY['[(80.12, 131.24), (201.5, 503.33)]']::lseg[], """ +
+ """ARRAY['(19.84, 11.23), (20.21, 2.1)']::box[], """ +
+ """ARRAY['(10.2, 30.4), (50.6, 70.8), (90.1, 11.3)']::path[], """ +
+ """ARRAY['((100.3, 40.2), (20.198, 83.1), (500.821, 311.38))']::polygon[], """ +
+ """ARRAY['<500, 200, 100>']::circle[], """ +
+ """ARRAY['16/B374D848']::pg_lsn[], """ +
+ """ARRAY[B'101010']::bit varying(6)[], """ +
+ """ARRAY['1 day', '2 minutes']::interval[], """ +
+ """ARRAY['08:00:2b:01:02:03:04:05']::macaddr8[], """ +
+ """ARRAY['10:20:10,14,15']::pg_snapshot[])"""
).executeUpdate()
conn.prepareStatement("CREATE TABLE char_types (" +
@@ -262,6 +282,27 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationSuite {
assert(rows(0).getSeq(7) == Seq("192.168.0.0/24", "10.1.0.0/16"))
assert(rows(0).getSeq(8) == Seq("""{"a": "foo", "b": "bar"}""", """{"a": 1, "b": 2}"""))
assert(rows(0).getSeq(9) == Seq("""{"a": 1, "b": 2, "c": 3}"""))
+ assert(rows(0).getSeq(10) == Seq("""id10"""))
+ assert(rows(0).getSeq(11) == Seq("'The' 'dog' 'grass' 'laying' 'on' 'the'",
+ "'cat':2 'is':3 'on':4 'table':6 'the':1,5"))
+ assert(rows(0).getSeq(12) == Seq("'programming' & 'language' & !'interpreter'",
+ "'cat':AB & 'dog':CD"))
+ assert(rows(0).getSeq(13) == Seq("12:34:56:78:90:ab", "cd:ef:12:34:56:78"))
+ assert(rows(0).getSeq(14) == Seq("10:20:10,14,15"))
+ assert(rows(0).getSeq(15) == Seq("(800.0,600.0)", "(83.24,5.1)"))
+ assert(rows(0).getSeq(16) == Seq("{-4.359313077939234,-1.0,159.9516512549538}",
+ "{23.85,10.87,5.92}"))
+ assert(rows(0).getSeq(17) == Seq("[(80.12,131.24),(201.5,503.33)]"))
+ assert(rows(0).getSeq(18) == Seq("(20.21,11.23),(19.84,2.1)"))
+ assert(rows(0).getSeq(19) == Seq("((10.2,30.4),(50.6,70.8),(90.1,11.3))"))
+ assert(rows(0).getSeq(20) == Seq("((100.3,40.2),(20.198,83.1),(500.821,311.38))"))
+ assert(rows(0).getSeq(21) == Seq("<(500.0,200.0),100.0>"))
+ assert(rows(0).getSeq(22) == Seq("16/B374D848"))
+ assert(rows(0).getSeq(23) == Seq("101010"))
+ assert(rows(0).getSeq(24) == Seq("0 years 0 mons 1 days 0 hours 0 mins 0.00 secs",
+ "0 years 0 mons 0 days 0 hours 2 mins 0.00 secs"))
+ assert(rows(0).getSeq(25) == Seq("08:00:2b:01:02:03:04:05"))
+ assert(rows(0).getSeq(26) == Seq("10:20:10,14,15"))
}
test("query JDBC option") {
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala
index ee8cbed1ff7a1..f47a13d062d7e 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala
@@ -57,7 +57,10 @@ private object PostgresDialect extends JdbcDialect {
case "int8" | "oid" => Some(LongType)
case "float4" => Some(FloatType)
case "money" | "float8" => Some(DoubleType)
- case "text" | "varchar" | "char" | "bpchar" | "cidr" | "inet" | "json" | "jsonb" | "uuid" =>
+ case "text" | "varchar" | "char" | "bpchar" | "cidr" | "inet" | "json" | "jsonb" | "uuid" |
+ "xml" | "tsvector" | "tsquery" | "macaddr" | "macaddr8" | "txid_snapshot" | "point" |
+ "line" | "lseg" | "box" | "path" | "polygon" | "circle" | "pg_lsn" | "varbit" |
+ "interval" | "pg_snapshot" =>
Some(StringType)
case "bytea" => Some(BinaryType)
case "timestamp" | "timestamptz" | "time" | "timetz" => Some(TimestampType)