Table "public.member_info" Table "public.address_info" プリペアド文

testdb=# \d member_info
                              Table "public.member_info"
  Column   |  Type   | Collation | Nullable |                 Default                 
-----------+---------+-----------+----------+-----------------------------------------
 id        | integer |           | not null | nextval('member_info_id_seq'::regclass)
 name      | text    |           |          | 
 groupid   | integer |           |          | 
 addressid | integer |           |          | 
testdb=# SELECT * FROM member_info;
 id | name | groupid | addressid 
----+------+---------+-----------
  1 | 田中 |     103 |      1001
  2 | 島野 |     101 |      1002
  3 | 森川 |     103 |      1004
  4 | 丸山 |     102 |      1001
(4 rows)
testdb=# \d address_info
                Table "public.address_info"
  Column   |     Type     | Collation | Nullable | Default 
-----------+--------------+-----------+----------+---------
 addressid | integer      |           |          | 
 postnum   | character(7) |           |          | 
 address   | text         |           |          | 
testdb=# SELECT * FROM address_info;
 addressid | postnum | address  
-----------+---------+----------
      1001 | 2061111 | 東京都
      1002 | 2062222 | 神奈川県
      1004 | 2064444 | 広島県
      1003 | 2063333 | 京都府
testdb=# PREPARE sample_prepare(VARCHAR) AS SELECT member_info.name, address_info.address
testdb-# FROM member_info, address_info
testdb-# WHERE member_info.addressid = address_info.addressid AND address_info.address = $1;
PREPARE
testdb=# EXECUTE sample_prepare('東京都');
 name | address 
------+---------
 田中 | 東京都
 丸山 | 東京都
(2 rows)

いいなと思ったら応援しよう!