Insert data into a table

Use a parameterized SQL statement to insert a new row of data into a table. Parameterized queries help prevent SQL injection attacks by treating user-provided values as data rather than executable code.

Code sample

Go

To authenticate to AlloyDB, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

insertVote := "INSERT INTO votes(candidate, created_at) VALUES($1, NOW())"
_, err := db.Exec(insertVote, team)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.