Skip to content

Commit 192b262

Browse files
HielkeJkaylareopellearielvalentin
authored
fix: get correct table name if table name is quoted (#1234)
* fix: get correct table name if table name is quoted * Remove double test * Add new line to sql_table_name.json * Stop accepting table name in single quotes --------- Co-authored-by: Kayla Reopelle <[email protected]> Co-authored-by: Ariel Valentin <[email protected]>
1 parent 7ad08f9 commit 192b262

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

instrumentation/pg/lib/opentelemetry/instrumentation/pg/patches/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Patches
1515
# Module to prepend to PG::Connection for instrumentation
1616
module Connection # rubocop:disable Metrics/ModuleLength
1717
# Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands
18-
TABLE_NAME = /\b(?:FROM|INTO|UPDATE|CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?|DROP\s+TABLE(?:\s+IF\s+EXISTS)?|ALTER\s+TABLE(?:\s+IF\s+EXISTS)?)\s+([\w\.]+)/i
18+
TABLE_NAME = /\b(?:FROM|INTO|UPDATE|CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?|DROP\s+TABLE(?:\s+IF\s+EXISTS)?|ALTER\s+TABLE(?:\s+IF\s+EXISTS)?)\s+["]?([\w\.]+)["]?/i
1919

2020
PG::Constants::EXEC_ISH_METHODS.each do |method|
2121
define_method method do |*args, &block|

instrumentation/pg/test/fixtures/sql_table_name.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,9 @@
5050
{
5151
"name": "from_with_join",
5252
"sql": "SELECT columns FROM test_table JOIN table2 ON test_table.column = table2.column"
53+
},
54+
{
55+
"name": "table_name_with_double_quotes",
56+
"sql": "SELECT columns FROM \"test_table\""
5357
}
54-
]
58+
]

0 commit comments

Comments
 (0)