Thursday, May 17, 2012

My note of postgresql

oracle sysdate => now()

trunc(sysdate) => date_trunc('day', now());

rownum

SELECT 
    row_number() OVER () AS i, 
    e.col1, 
    e.col2, 
    ... FROM ... 



select ... from .. LIMIT 100;

sequence_name.nextval() => nextval('sequence_name')



java -jar /path/to/schemaSpy_5.0.0.jar -t pgsql -host MYHOSTNAME -db DBNAME -s SCHEMANAME -u USERNAME -p PASSWORD -o /path/to/output/directory -dp /path/to/postgresql-9.1-902.jdbc3.jar -charset utf-8


import
=====
copy {table_name}
from '/path/to/file.csv'
DELIMITER ',' CSV;



thanks
 http://stackoverflow.com/questions/3959692/rownum-in-postgresql

Wednesday, May 16, 2012

HTML ภาษาไทย


<head>
<meta http-equiv="Content-Language" content="th">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>

Wednesday, May 9, 2012

Cannot Connect PostgreSQL Remotely

could not connect to server: Connection refused Is the server running on host "......" (......) and accepting TCP/IP connections on port ....?

Solution
========
sudo vi /etc/postgresql/8.4/main/postgresql.conf

listen_addresses = '*'
port = 5432



After changing this file, you need to restart the server process to make the setting effective.

sudo service postgresql start



Note from pgadmin3
===================
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.

For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses.


Other Related Info
===================
sudo vi /etc/postgresql/8.4/main/pg_hba.conf

to allow connections from any remote address.
host all all 0.0.0.0/0 md5

psql -U {username} -h {hostname} -D {database_name}


thanks http://kb.mediatemple.net/questions/1237/How+do+I+enable+remote+access+to+my+PostgreSQL+server%3F#dv