Learning Golang: Relational Databases - Bulk Insert with PostgreSQL

Опубликовано: 31 Октябрь 2024
на канале: Mario Carrion
6,207
114

Let's learn about Bulk Insert in Relational Databases using Go/Golang specifically using the "pgx" package, but also why using the concrete database engine is better than using a bunch of INSERT commands via "database/sql"

This episode covers the concrete methods defined in "pgx" to deal with Bulk Inserts, specifically using the COPY command via the "Conn.CopyFrom" method that requires the following:

tableName Identifier
columnNames []string
rowSrc CopyFromSource

Where "CopyFromSource" is a type that we must implement, sort of a reader that indicates "pgx" how to deal with the individual records.

== Relevant links

Example code: https://github.com/MarioCarrion/video...
Relational Databases - Bulk Insert -    • Learning Golang: Relational Databases...  

PostgreSQL driver and toolkit for Go: https://github.com/jackc/pgx
Previous Episode: "Learning Golang: Relational Databases - Transactions with PostgreSQL":    • Learning Golang: Relational Databases...  
"Software Architecture in Golang: Security - Databases, SQL Injection and Permissions"    • Software Architecture in Golang: Secu...  
"Learning Golang: Context package: Cancellations, Deadlines and Request-scoped values"    • Learning Golang: Context package: Can...  

== All Go/Golang video series covered

Playlist "Learning Go":    • Learning Go/Golang  
Playlist "Software Architecture in Go":    • Software Architecture and System Desi...  
Playlist "Learning Go/Golang Concurrency Patterns"    • Learning Go/Golang Concurrency Patterns  
Playlist "Building Microservices in Go":    • Building Microservices in Golang/Go  
Playlist "GoTools and Packages":    • Golang/Go Tools and Packages  
Playlist "Testing in Go":    • Testing in Golang/Go  

== Socials

  / mariocarrion  
  / mario.carrion  
  / mariocarrion  

00:00 - Start
01:00 - Bulk Insert using database/sql via jackc/pgx (inefficient)
11:44 - Bulk Insert using jackc/pgx (efficient)
21:03 - Conclusions

---

Who am I:

Hello👋🏼! I'm Mario, a Hands-on Software Architect and Lead Backend Engineer with more than 16 years of professional experience building all kinds of software including on-premise Industrial Automation Systems, Linux Accessibility Desktop and Browser Components as well as Distributed Advertising Microservices.

Every week I will share with you different topics I've learned while working for small startups and large companies including the processes I've followed over the years for successfully delivering complex enterprise systems from start to end.

Subscribe if you like Software Development, Software Architecture and Systems Design!

Keep it up. Don't give up!

#golang #tutorial #databases

=== Our Vlog Channel

   / rubycarrion  

=== Our affiliate links below

■ My Amazon Storefront: https://www.amazon.com/shop/rubycarrion
■ Shop my IG posts on my shopLTK page: https://www.shopltk.com/explore/RubyC...
■ Vlog camera: Sony RX100 VII https://amzn.to/3qQfvMc
■ Other vlog cameras and gear: https://rubycarrion.com/vlogcamerasan...
■ Shop through my links to support the channel: https://rubycarrion.com/shop-my-links/
■ Get a 30 day FREE Trial of Epidemic Sound: https://www.epidemicsound.com/referra...
■ Join Rakuten for FREE and get $30 when you spend $30: https://www.rakuten.com/r/RUBYRA132?e...

DISCLAIMER: Some of the links shared in the description are affiliate links. As a member of these affiliate programs, I earn a small commission from your purchases at no additional cost to you. I appreciate your support! 💖