
PostgreSQLでテーブルにデータをINSERTします。
テーブルのカラムの情報を確認する!
データをINSERTするauthenticationテーブルのカラムの情報を確認します。
inventory=# \d authentication
                       Table "public.authentication"
   Column   |            Type             | Collation | Nullable | Default 
------------+-----------------------------+-----------+----------+---------
 user_id    | character varying(50)       |           | not null | 
 username   | character varying(50)       |           | not null | 
 password   | character varying(50)       |           | not null | 
 email      | character varying(255)      |           | not null | 
 created_on | timestamp without time zone |           | not null | 
 last_login | timestamp without time zone |           |          | 
Indexes:
    "authentication_pkey" PRIMARY KEY, btree (user_id)
    "authentication_email_key" UNIQUE CONSTRAINT, btree (email)
    "authentication_username_key" UNIQUE CONSTRAINT, btree (username)
データをINSERTする!
authenticationテーブルにデータをINSERTします。
inventory=# insert into authentication (user_id, username, password, email, created_on, last_login) values ('00000001', 'sysusr01', 'sysusr01', 'lab4ict@gmail.com', '2023-05-09 00:00:00', '2023-05-09 00:00:00');
INSERT 0 1
データを確認する!
INSERTしたデータをSELECT文で確認します。
inventory=# select * from authentication; user_id | username | password | email | created_on | last_login ----------+----------+----------+-------------------+---------------------+--------------------- 00000001 | sysusr01 | sysusr01 | lab4ict@gmail.com | 2023-05-09 00:00:00 | 2023-05-09 00:00:00 (1 row)
おわりに
PostgreSQLのテーブルへのデータINSERTは、標準的なSQL文で実行することができます。
参考情報
関連記事
参考書籍(Amazon)

