aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pgtclsh/pgtclUtils.tcl
blob: e09e8b2b3a2e79177b845c93d794e78cd70aed53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# getDBs :
#   get the names of all the databases at a given host and port number
#   with the defaults being the localhost and port 5432
#   return them in alphabetical order
proc getDBs { {host "localhost"} {port "5432"} } {
    # datnames is the list to be result
    set conn [pg_connect template1 -host $host -port $port]
    set res [pg_exec $conn "SELECT datname FROM pg_database ORDER BY datname"]
    set ntups [pg_result $res -numTuples]
    for {set i 0} {$i < $ntups} {incr i} {
	lappend datnames [pg_result $res -getTuple $i]
    }
    pg_result $res -clear
    pg_disconnect $conn
    return $datnames
}