-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix postgres_cdc
input
#3075
Fix postgres_cdc
input
#3075
Conversation
c8148a6
to
22076dc
Compare
Allow quoted identifiers for the table names Signed-off-by: Mihai Todor <[email protected]>
22076dc
to
ec0d162
Compare
99f61fc
to
d8f02c4
Compare
There is currently a mess of "what does this string mean?", which means it's time to introduce some typesafety to this problem. TableFQN is a Schema+Table pair that is prevalidated to not have SQL injection opportunities and we can pass these around to make things a bit more clear as well as ensure we're handling quoted stuff correctly.
d8f02c4
to
20e90bf
Compare
Okay updates here:
|
I also updated one of our integration tests to use a PascalCase name to codify the test that Mihai wrote in the PR. thank you @mihaitodor for this! If you have time today can you double check my commits look OK? If so please merge. |
b654c6d
to
9b77304
Compare
Technically this also opens us up to allowing a single input with different schemas - not sure if you see that as needed @ligfx |
Signed-off-by: Mihai Todor <[email protected]>
Signed-off-by: Mihai Todor <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me and works for me locally. Love the normalization of passed in identifiers.
@@ -363,28 +363,72 @@ func SQLQuery(sql string, args ...any) (string, error) { | |||
return query.Sanitize(args...) | |||
} | |||
|
|||
// ValidatePostgresIdentifier checks if a string is a valid PostgreSQL identifier | |||
// QuotePostgresIdentifier returns the valid escaped identifier. | |||
func QuotePostgresIdentifier(name string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return `"` + name.Replace(`"`, `""`) + `"`
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's simpler. This happens to be faster, but this isn't on a critical path. I'll fix it next time I hack on this input
90218b1
to
9e48cc7
Compare
e15bfa5
to
5606ca9
Compare
Allow quoted identifiers for the table names.
Note: This is a very naive implementation and we might want to instead just quote the identifier like @rockwotj suggested (and implemented here for Snowflake).
If we always quote, then it's a bit unclear how to validate the identifiers because we can't tell when it genuinely needs to be quoted to apply the alternate validation rules: https://www.postgresql.org/docs/current/sql-syntax-lexical.html
Also, users might get confused if they specify the table name as upper case in the config for a non-quoted table:
How to test
Run Postgres and connect to it via
pgcli
:$ docker run --rm -it -e POSTGRES_USER=testuser -e "POSTGRES_PASSWORD=testpass" -e POSTGRES_DB=testdb -p5432:5432 postgres -c wal_level=logical $ pgcli postgres://testuser:testpass@localhost:5432/testdb
Create a quoted table:
Run Connect:
Insert rows:
Comment out the
"BarFoo"
table in the Connect config, restart it and insert another row in"FooBar"
.