Began to learn Python 2.7 + PostgreSQL 9.6.1. Python already has some experience, but I don’t have any experience with PostgreSQL. Is it possible to create a database with connections at all?
I create a database with the following code, but how to add tables to it (with the definition of data types) and the relations between them:
#!/usr/bin/python # -*- coding: utf-8 -*- from psycopg2 import connect import sys from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT con = None con = connect(user='postgres', password='poilk', port=5432) dbname = "name_db" con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) cur = con.cursor() cur.execute('CREATE DATABASE ' + dbname) cur.close() con.close() For example: how to create in Python 2 tables with a one-to-many relationship in the database:
Table 1 - user_name (ID, name, password)
Table 2 - additionally (age, sex, hp, items, knowledge)
psycopg2? Are you interested in which SQL query you need to write to create a table? Then ask about this (remove everything else). If you know how to create a table, then give a sample code for the two specified tables. How to express a one-to-many relation in SQL (a dialect supported by Postgres) for the specified tables is a separate question. (By the way, describe what is connected with what: do you want one user to be associated with several characters, with given ages, sex, etc. be connected?) - jfs