Skip to content

Commit 968e5bf

Browse files
committed
Quote publication names as identifiers in SQL statements
So that publication names with special characters can be created
1 parent 25fbd1c commit 968e5bf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

postgresql/resource_postgresql_publication.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func setPubOwner(txn *sql.Tx, d *schema.ResourceData) error {
158158
n := nraw.(string)
159159
pubName := d.Get(pubNameAttr).(string)
160160

161-
sql := fmt.Sprintf("ALTER PUBLICATION %s OWNER TO %s", pubName, n)
161+
sql := fmt.Sprintf("ALTER PUBLICATION %s OWNER TO %s", pq.QuoteIdentifier(pubName), n)
162162
if _, err := txn.Exec(sql); err != nil {
163163
return fmt.Errorf("Error updating publication owner: %w", err)
164164
}
@@ -183,12 +183,12 @@ func setPubTables(txn *sql.Tx, d *schema.ResourceData) error {
183183
added := arrayDifference(newList, oldList)
184184

185185
for _, p := range added {
186-
query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pubName, quoteTableName(p.(string)))
186+
query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pq.QuoteIdentifier(pubName), quoteTableName(p.(string)))
187187
queries = append(queries, query)
188188
}
189189

190190
for _, p := range dropped {
191-
query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pubName, quoteTableName(p.(string)))
191+
query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pq.QuoteIdentifier(pubName), quoteTableName(p.(string)))
192192
queries = append(queries, query)
193193
}
194194

@@ -202,13 +202,12 @@ func setPubTables(txn *sql.Tx, d *schema.ResourceData) error {
202202

203203
func setPubParams(txn *sql.Tx, d *schema.ResourceData, pubViaRootEnabled bool) error {
204204
pubName := d.Get(pubNameAttr).(string)
205-
paramAlterTemplate := "ALTER PUBLICATION %s %s"
206205
publicationParametersString, err := getPublicationParameters(d, pubViaRootEnabled)
207206
if err != nil {
208207
return fmt.Errorf("Error getting publication parameters: %w", err)
209208
}
210209
if publicationParametersString != "" {
211-
sql := fmt.Sprintf(paramAlterTemplate, pubName, publicationParametersString)
210+
sql := fmt.Sprintf("ALTER PUBLICATION %s %s", pq.QuoteIdentifier(pubName), publicationParametersString)
212211
if _, err := txn.Exec(sql); err != nil {
213212
return fmt.Errorf("Error updating publication parameters: %w", err)
214213
}
@@ -240,7 +239,7 @@ func resourcePostgreSQLPublicationCreate(db *DBConnection, d *schema.ResourceDat
240239
}
241240
defer deferredRollback(txn)
242241

243-
sql := fmt.Sprintf("CREATE PUBLICATION %s %s %s", name, tables, publicationParameters)
242+
sql := fmt.Sprintf("CREATE PUBLICATION %s %s %s", pq.QuoteIdentifier(name), tables, publicationParameters)
244243

245244
if _, err := txn.Exec(sql); err != nil {
246245
return fmt.Errorf("Error creating Publication: %w", err)

0 commit comments

Comments
 (0)