Skip to content

🐘 Introductory examples for people who want to use PostgreSQL with the C language. In the examples, the most basic operations to manage the database were covered, namely: connecting, creating tables, inserting records, selecting data, updating and deleting records.

License

Notifications You must be signed in to change notification settings

melchisedech333/c-postgresql

Repository files navigation




Language: PT-BR

The purpose of the codes in this repository is to provide a set of code examples for anyone starting to use PostgreSQL with the C language.

If my code has helped you, please consider sponsoring me 💙


📑 Table of Contents



⭐ General notions


To install PostgreSQL on Linux (Debian/Ubuntu based distributions) you can run the commands below.

sudo apt install postgresql postgresql-contrib
sudo apt install libpq-dev

Connect to server:

sudo -u postgres psql

When accessing the server, you can use these commands below to manage it.

\l                     Lists the databases.
\c DB_NAME             Connects to an existing database.
\dt                    Lists existing tables.
\q                     Log out of the server.

📋 Description of files

General use:

  • build.sh: Generate executables (compile).
  • settings.h: Header containing PostgreSQL server settings.

Codes:

  • 1 - connect.c: Makes the connection to the server.
  • 2 - create table.c: Creates and deletes a table in the database.
  • 3 - insert item.c: Insert records into a table.
  • 4 - select all.c: Selects records from a table.
  • 5 - delete.c: Delete records.
  • 6 - update.c: Update records.

🔨 Compiling the codes

To compile the codes, just run the build.sh script, specifying in its parameters the name of the file you want to compile, as in the example below.

./build.sh "1 - connect.c"

The compiled file is always saved with the name app-test, so just run it to run the tests.

./app-test

🔗 References and Links

ZetCode, PostgreSQL programming in C


😃 Author

Sponsor: melchisedech333
Twitter: Melchisedech333
LinkedIn: Melchisedech Rex
Blog: melchisedech333.github.io


📜 License

BSD-3-Clause license



Remember to give me
a beautiful little star 🤩

About

🐘 Introductory examples for people who want to use PostgreSQL with the C language. In the examples, the most basic operations to manage the database were covered, namely: connecting, creating tables, inserting records, selecting data, updating and deleting records.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project