Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🐘 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

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /