プロが教えるわが家の防犯対策術!

皆様始めまして~初歩的な質問かもしれないですが
postgresSQLのデータをpsqlコマンドでみるときに
whereをつかわずに

[xxxxxxx@yyyyyy ~]$ psql -q -c 'select * from employ_kanri' xxxxxx postgres
社員名 | 社員番号 | 勤務先
------------------------+--------------+----------------------------
田中 | 200700 | 横浜

と結果はでるのに、

whereを使うと
[xxxxxxxx@yyyyy ~]$ psql -q -c 'select * from employ_kanri where 勤務先 = '横浜'' xxxxxx postgres
ERROR: column "横浜" does not exist

になるのはなぜでしょうか?

ちなみにデータベースに入ってwhereコマンドを使うと問題なくできます。。
[xxxxxxx@yyyyyyy ~]$ psql xxxxxx postgres
Welcome to psql 7.4.11, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

xxxxxxx=# select * from employ_kanri where 勤務先 = '横浜';
社員名 | 社員番号 | 勤務先
------------------------+--------------+----------------------------
田中 | 200700 | 横浜

よろしくお願いします

A 回答 (1件)

Postgre使ったこと無いですが



psql -q -c "select * from employ_kanri where 勤務先 = '横浜'"

単にこういう事では?
外をシングルコーテーションで括っているのに、中でも使ったら
そこで終了と見なされると思います。

この回答への補足

早速のアドバイスありがとうございます。
上記の内容はできました。本当にありがとうございます。
お手数ですが、もう1つだけ質問さしてください
DBに接続してselect文をするperlをつくったんですが
なぜかコンパイルの際にエラーがでます。内容は

[xxxxxxxx@delsol DB]$ ./select.pl
DBD::Pg::st fetchrow_array failed: no statement executing
DBI handle 0x8aa61b0 has uncleared implementors data.
dbih_clearcom (sth 0x8aa61b0, com 0x8aafc70, imp DBD::Pg::st):
FLAGS 0x80113: COMSET IMPSET Warn PrintError
PARENT DBI::db=HASH(0x8aa609c)
KIDS 0 (0 Active)
IMP_DATA undef
NUM_OF_FIELDS -1
NUM_OF_PARAMS 0

これはどういう意味なんでしょうか?調べてものっていませんでした。
参考にソースを添付します。

#! /usr/local/bin/perl

use DBI;

$dbname = "xxxxxxxx";

$host = "zzzzzzz";
$user = "postgres";
$password = "";

$dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host", $user, $password );

$sth = $dbh->prepare("select * from employ_kanri where 社員名 = '田中'");

$sth->execute;

while (@row = $sth->fetchrow_array){
print "@row\n";
}

$sth->finish;

よろしくお願いします。

補足日時:2008/07/07 16:42
    • good
    • 0
この回答へのお礼

早速のアドバイスありがとうございます。
上記の内容はできました。本当にありがとうございます。
お手数ですが、もう1つだけ質問さしてください
DBに接続してselect文をするperlをつくったんですが
なぜかコンパイルの際にエラーがでます。内容は

[xxxxxxxx@delsol DB]$ ./select.pl
DBD::Pg::st fetchrow_array failed: no statement executing
DBI handle 0x8aa61b0 has uncleared implementors data.
dbih_clearcom (sth 0x8aa61b0, com 0x8aafc70, imp DBD::Pg::st):
FLAGS 0x80113: COMSET IMPSET Warn PrintError
PARENT DBI::db=HASH(0x8aa609c)
KIDS 0 (0 Active)
IMP_DATA undef
NUM_OF_FIELDS -1
NUM_OF_PARAMS 0

これはどういう意味なんでしょうか?調べてものっていませんでした。
参考にソースを添付します。

#! /usr/local/bin/perl

use DBI;

$dbname = "xxxxxxxx";

$host = "zzzzzzz";
$user = "postgres";
$password = "";

$dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host", $user, $password );

$sth = $dbh->prepare("select * from employ_kanri where 社員名 = '田中'");

$sth->execute;

while (@row = $sth->fetchrow_array){
print "@row\n";
}

$sth->finish;

よろしくお願いします。

お礼日時:2008/07/07 16:57

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!