Help us understand the problem. What is going on with this article?

Python3.6で、Centos上のpostgresqlへ接続テスト

Python3.6で、Centos上のpostgresqlへ接続テスト

事前に、VirtualBox上のCentOS7.6をインストールして
postgreSQLをソースからコンパイルしている。これについては別途記事を書く

PostgreSQL 11.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit

スクリーンショット 2019-09-19 20.52.36.png

データベースの作成

create database mei_edinet_db;

大文字は使えない
image.png

psycopg2のインストール

Windows側のDOSプロンプトで

pip install psycopg2

スクリーンショット 2019-09-19 20.57.20.png

ヲタクテーブルを作成しておく

CREATE TABLE wotaku (
tid text NOT NULL,
wota_name text NOT NULL
);
ALTER TABLE ONLY wotaku
ADD CONSTRAINT wotaku_pkey PRIMARY KEY (tid);

スクリーンショット 2019-09-20 19.42.51.png

test_posdb.py
import psycopg2
conn = psycopg2.connect("host=192.168.10.8 port=5432 dbname=mei_edinet_db user=mayser")
cur = conn.cursor()
cur.execute("SELECT tid, wota_name FROM wotaku;")
for row in cur:
    print(row)

cur.close()
conn.close()

結果

('code2545Light', 'メイザー☆SKKS')

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away