Cloud Nine

Avatar

About IT things and others.

PostgreSQL 8.1.3→PostgreSQL 9.1.2に変更したらJoinでトラブった件
3月 23, 2012 0

先月、とあるシステムをPostgreSQL 8.1.3→PostgreSQL 9.1.2にアップグレードしたら、既存システムが動かなくなった。
よく調べてみるとSQLのJoin部分のKeyの型がcharacterだと接続エラーになっていました。

解決方法

で、単純に下記のSQLで型を変更しようと思ったのですが、場所によっては下記のSQLでは型変更ができないところがありました。

ALTER TABLE toiawase ALTER COLUMN kokyaku_id TYPE integer USING kokyaku_id::integer;

解決方法(IndexやViewがある場合)

また調べてみると変更しようとしたKeyがIndexやViewの中でも使用されていることが判明
なので、変更対象のKeyが使用されているIndexやViewをいったん削除して、上記SQLを再度実行して、その後に、削除したIndexやViewを復元させて、
事無きを得ました。ちゃんちゃん

#Indexの削除
DROP INDEX name toiawase_Index;

#型の変更
ALTER TABLE toiawase ALTER COLUMN kokyaku_id TYPE integer USING kokyaku_id::integer;

#Indexの作成
CREATE INDEX toiawase_Index ON toiawase USING btree (kokyaku_id);

How to make testing environment about Postgres.
3月 31, 2009 0

I often use postgres server,so sometimes I have to make testing environment for postgres in my windows pc.
So I want to write how to make testing environment about Postgres for my memo.

postgres

First Step

Please login postgres server, and then you have to change user what this user is postgres user.
And I use pg_dump.

# pg_dump -f filename.sql.gz -Z 1 -c database-name

-f to write file about output.
-Z。。Number this is level of compression.
-c it is cleaning for schema.

Second Step

You get dump file from server.And then you decompress file.

Third Step

You install postgres in your windows PC. Please check Postgres sites.

Fourth Step

Please copy dump file to there.

\Program Files\PostgresSQL\8.3\bin\

And please open command prompt and write this command.

cd \Program Files\PostgresSQL\8.3\bin\
psql dbname < dumpfile

That's all!!!

And if you see these message.Please make user on for postgres.
psql: FATAL: role "・譯シ・カフセ" does not exist、ネクタ、??ソ、饅r

Or

please change user what this user is postgres user.

psql -u

初心者用pg_dumpの方法
4月 30, 2008 0

pg_dumpは

pg_dump database_name > database_name.sql

を実行すればできると、あるが実際はいろいろと気をつけないことが、たくさんあるのでそのメモ

その一、ユーザの準備
postgresでDBを作成しているなら、postgresユーザがいります。

useradd -d /home/postgres/ postgres

このときに、ホームディレクトリーも作っておきます。

その二、ファイルの準備
先ほど上のつくったホームディレクトリーの中にdatabase_name.sqlのファイルを作っておきます。

touch database_name.sql

その三、bushが引けてない場合があるのでlocateでpg_dumpを調べてひいいておきましょう。

その四、いざ実行

[postgres@www postgres]$ pg_dump database_name.sql > database_name.sql

LIKE検索について
1月 30, 2008 0

今までのLIKE検索の仕方

(  company LIKE '%".$word."%' OR  address LIKE '%".$word."%' OR  owner LIKE '%".$word."%'  OR   url LIKE '%".$word."%' OR  title LIKE  %".$word."%')";

 ↓
こうすればよかったんですね。

(company ||  address || owner ||  url || title  ILIKE ('%".$value."%'))";

文字列をSQLクエリー用にエスケープしたい。
1月 29, 2008 0

//Postgresのエスケープ

pg_escape_string($str);

//Mysqlのエスケープ

mysql_escape_string($str);

Real Time Analytics