Skip to content

Commit

Permalink
RD-10568 Sql auto-complete shows postgres internal tables (#357)
Browse files Browse the repository at this point in the history
Added a where clause in the queries for the auto-complete filtering out
information_schema and pg_catalog
  • Loading branch information
torcato authored Feb 12, 2024
1 parent 2ffb90d commit d421bd8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ object DotSearchWithOneItem
extends Completion(
"""SELECT item1, item2, type FROM (
| -- tables that belong to schemas having that name
| SELECT table_schema AS item1, table_name AS item2, 'table' AS type FROM information_schema.tables WHERE table_schema = ?
| SELECT table_schema AS item1, table_name AS item2, 'table' AS type FROM information_schema.tables
| WHERE table_schema = ?
| AND table_schema NOT IN ('pg_catalog', 'information_schema')
| UNION
| -- columns that belong to tables having that name
| SELECT table_name AS item1, column_name AS item2, data_type AS type FROM information_schema.columns WHERE table_name = ?) T""".stripMargin
| SELECT table_name AS item1, column_name AS item2, data_type AS type FROM information_schema.columns
| WHERE table_name = ?
| AND table_schema NOT IN ('pg_catalog', 'information_schema')
|) T""".stripMargin
) {
override protected def setParams(preparedStatement: PreparedStatement, items: Seq[String]): Unit = {
val item = items.head
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ object DotSearchWithTwoItems
"""-- columns that belong to tables having the required name in schemas having the required name
|SELECT table_schema, table_name, column_name, data_type AS type
|FROM information_schema.columns
|WHERE table_schema = ? AND table_name = ?""".stripMargin
|WHERE table_schema = ?
| AND table_name = ?
| AND table_schema NOT IN ('pg_catalog', 'information_schema')""".stripMargin
) {
override protected def setParams(preparedStatement: PreparedStatement, items: Seq[String]): Unit = {
val item1 = items(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ object WordSearchWithOneItem
extends Completion(
"""SELECT name, type FROM (
|-- schemas that have a name starting with the identifier
|SELECT schema_name AS name, 'schema' AS type FROM information_schema.schemata WHERE starts_with(schema_name, ?)
|SELECT schema_name AS name, 'schema' AS type FROM information_schema.schemata
| WHERE starts_with(schema_name, ?) AND schema_name NOT IN ('pg_catalog', 'information_schema')
|UNION
|-- tables that have a name starting with the identifier
|SELECT table_name AS name, 'table' AS type FROM information_schema.tables WHERE starts_with(table_name, ?)
|SELECT table_name AS name, 'table' AS type FROM information_schema.tables
| WHERE starts_with(table_name, ?) AND table_schema NOT IN ('pg_catalog', 'information_schema')
|UNION
|-- columns that have a name starting with the identifier
|SELECT column_name AS name, data_type AS type FROM information_schema.columns WHERE starts_with(column_name, ?)) T""".stripMargin
|SELECT column_name AS name, data_type AS type FROM information_schema.columns
| WHERE starts_with(column_name, ?) AND table_schema NOT IN ('pg_catalog', 'information_schema')
|) T""".stripMargin
) {
override protected def setParams(preparedStatement: PreparedStatement, items: Seq[String]): Unit = {
val item = items.head
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ object WordSearchWithThreeItems
|SELECT table_schema, table_name, column_name, data_type AS type FROM information_schema.columns
|WHERE table_schema = ?
| AND table_name = ?
| AND starts_with(column_name, ?)""".stripMargin
| AND starts_with(column_name, ?)
| AND table_schema NOT IN ('pg_catalog', 'information_schema')""".stripMargin
) {
override protected def setParams(preparedStatement: PreparedStatement, items: Seq[String]): Unit = {
val item1 = items(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ object WordSearchWithTwoItems
| -- tables having a similar name, that belong to schemas having the name
| SELECT table_schema AS item1, table_name AS item2, 'table' AS type
| FROM information_schema.tables
| WHERE table_schema = ? AND starts_with(table_name, ?)
| WHERE table_schema = ?
| AND starts_with(table_name, ?)
| AND table_schema NOT IN ('pg_catalog', 'information_schema')
| UNION
| -- columns having a similar name, that belong to tables having the name
| SELECT table_name AS item1, column_name AS item2, data_type AS type
| FROM information_schema.columns
| WHERE table_name = ? AND starts_with(column_name, ?)
| WHERE table_name = ?
| AND starts_with(column_name, ?)
| AND table_schema NOT IN ('pg_catalog', 'information_schema')
| ) T""".stripMargin
) {
override protected def setParams(preparedStatement: PreparedStatement, items: Seq[String]): Unit = {
Expand Down

0 comments on commit d421bd8

Please sign in to comment.