diff --git a/__fixtures__/generated/generated.json b/__fixtures__/generated/generated.json
index ff10c9fd..53e910a4 100644
--- a/__fixtures__/generated/generated.json
+++ b/__fixtures__/generated/generated.json
@@ -21225,6 +21225,23 @@
"misc/xml-indent-3.sql": "SELECT XMLSERIALIZE(CONTENT doc AS varchar INDENT) FROM xmltest",
"misc/xml-indent-4.sql": "SELECT XMLSERIALIZE(DOCUMENT '' AS text NO INDENT)",
"misc/xml-indent-5.sql": "SELECT XMLSERIALIZE(CONTENT '' AS text)",
+ "misc/typecast-1.sql": "SELECT CAST('(' AS text)",
+ "misc/typecast-2.sql": "SELECT CAST('(-)' AS text)",
+ "misc/typecast-3.sql": "SELECT CAST('-hello' AS text)",
+ "misc/typecast-4.sql": "SELECT CAST(\"a(b\" AS integer)",
+ "misc/typecast-5.sql": "SELECT -1::integer",
+ "misc/typecast-6.sql": "SELECT (-1)::integer",
+ "misc/typecast-7.sql": "SELECT -1.5::numeric",
+ "misc/typecast-8.sql": "SELECT (-1.5)::numeric",
+ "misc/typecast-9.sql": "SELECT (-0.0)::numeric",
+ "misc/typecast-10.sql": "SELECT (-9223372036854775808)::integer",
+ "misc/typecast-11.sql": "SELECT (1 + 2)::integer",
+ "misc/typecast-12.sql": "SELECT length('abc')::integer",
+ "misc/typecast-13.sql": "SELECT 'x'::pg_catalog.bpchar",
+ "misc/typecast-14.sql": "SELECT 'x'::pg_catalog.bpchar(3)",
+ "misc/typecast-15.sql": "SELECT 'x'::pg_catalog.bpchar[]",
+ "misc/typecast-16.sql": "SELECT 'x'::bpchar",
+ "misc/typecast-17.sql": "SELECT 'x'::app.some_type",
"misc/transaction-chain-1.sql": "COMMIT AND CHAIN",
"misc/transaction-chain-2.sql": "ROLLBACK AND CHAIN",
"misc/transaction-chain-3.sql": "END AND CHAIN",
diff --git a/__fixtures__/kitchen-sink/misc/typecast.sql b/__fixtures__/kitchen-sink/misc/typecast.sql
new file mode 100644
index 00000000..6cf20c4c
--- /dev/null
+++ b/__fixtures__/kitchen-sink/misc/typecast.sql
@@ -0,0 +1,21 @@
+-- Round-trip coverage for TypeCast syntax selection (#398).
+SELECT CAST('(' AS text);
+SELECT CAST('(-)' AS text);
+SELECT CAST('-hello' AS text);
+SELECT CAST("a(b" AS integer);
+
+-- Unary minus outside a cast is distinct from a negative cast argument.
+SELECT -1::integer;
+SELECT (-1)::integer;
+SELECT -1.5::numeric;
+SELECT (-1.5)::numeric;
+SELECT (-0.0)::numeric;
+SELECT (-9223372036854775808)::integer;
+
+SELECT (1 + 2)::integer;
+SELECT length('abc')::integer;
+SELECT 'x'::pg_catalog.bpchar;
+SELECT 'x'::pg_catalog.bpchar(3);
+SELECT 'x'::pg_catalog.bpchar[];
+SELECT 'x'::bpchar;
+SELECT 'x'::app.some_type;
diff --git a/packages/deparser/__tests__/kitchen-sink/misc-typecast.test.ts b/packages/deparser/__tests__/kitchen-sink/misc-typecast.test.ts
new file mode 100644
index 00000000..350d97dd
--- /dev/null
+++ b/packages/deparser/__tests__/kitchen-sink/misc-typecast.test.ts
@@ -0,0 +1,25 @@
+
+import { FixtureTestUtils } from '../../test-utils';
+const fixtures = new FixtureTestUtils();
+
+it('misc-typecast', async () => {
+ await fixtures.runFixtureTests([
+ "misc/typecast-1.sql",
+ "misc/typecast-2.sql",
+ "misc/typecast-3.sql",
+ "misc/typecast-4.sql",
+ "misc/typecast-5.sql",
+ "misc/typecast-6.sql",
+ "misc/typecast-7.sql",
+ "misc/typecast-8.sql",
+ "misc/typecast-9.sql",
+ "misc/typecast-10.sql",
+ "misc/typecast-11.sql",
+ "misc/typecast-12.sql",
+ "misc/typecast-13.sql",
+ "misc/typecast-14.sql",
+ "misc/typecast-15.sql",
+ "misc/typecast-16.sql",
+ "misc/typecast-17.sql"
+]);
+});
diff --git a/packages/transform-ast/__tests__/kitchen-sink/fixtures.json b/packages/transform-ast/__tests__/kitchen-sink/fixtures.json
index 23054325..7d1d0c84 100644
--- a/packages/transform-ast/__tests__/kitchen-sink/fixtures.json
+++ b/packages/transform-ast/__tests__/kitchen-sink/fixtures.json
@@ -21710,6 +21710,25 @@
"original/alter/alter-table-column-8.sql",
"original/alter/alter-table-column-9.sql"
],
+ "misc-typecast": [
+ "misc/typecast-1.sql",
+ "misc/typecast-2.sql",
+ "misc/typecast-3.sql",
+ "misc/typecast-4.sql",
+ "misc/typecast-5.sql",
+ "misc/typecast-6.sql",
+ "misc/typecast-7.sql",
+ "misc/typecast-8.sql",
+ "misc/typecast-9.sql",
+ "misc/typecast-10.sql",
+ "misc/typecast-11.sql",
+ "misc/typecast-12.sql",
+ "misc/typecast-13.sql",
+ "misc/typecast-14.sql",
+ "misc/typecast-15.sql",
+ "misc/typecast-16.sql",
+ "misc/typecast-17.sql"
+ ],
"misc-rename-qualified-and-sequence-privs": [
"misc/rename-qualified-and-sequence-privs-1.sql",
"misc/rename-qualified-and-sequence-privs-2.sql",