Alaska Software Inc. - List of Databases in Postgresql.
Username: Password:
AuthorTopic: List of Databases in Postgresql.
César Calvo List of Databases in Postgresql.
on Tue, 01 Nov 2016 21:24:34 +0100
Hello Friends.

Does anybody knows the way for know if a database exists in postgresql with 
SQL Commands via ODBC?

I suppose that there is a system table where we can search the name of 
databases in the server or something like this.

Thanks.
César.
César Calvo Re: List of Databases in Postgresql.
on Wed, 02 Nov 2016 00:02:06 +0100
Hi,

I got it with SqlExpress

PROCEDURE PROCESO()
LOCAL cSIP, oConStr, cConStr, oCon, cSql, oCur, oStmt, dbQuery, cCon, oSes, 
nCol, A, B

 Conecta con PostGreSql

cConStr := "Driver={Advantage StreamlineSQL ODBC};DataDirectory=" + 
trim(cDirDB);CharSet=OEM;MemoBlockSize=64;MaxTableCloseCache=20" + ;
               ";DefaultType=FoxPro;Rows=False;AdvantageLocking=ON;Locking=Record;ServerTypes=2;TrimTrailingSpaces=False;RightsChecking=OFF;"

oCon := SQLConnection():new()

IF oCon:DriverConnect(nil,cConStr)

   Infobox("Conectado")

   cSql := "SELECT * FROM pg_database ORDER BY datname"

   oCur := oCon:Cursor(cSql)

   IF oCur:Seek("dbftid")
      Infobox("Existe")
      ELSE
      Infobox("No Existe")
   ENDIF


"César Calvo"  escribió en el mensaje de 
noticias:c899c23$73221571$e74d8@news.alaska-software.com...

Hello Friends.

Does anybody knows the way for know if a database exists in postgresql with
SQL Commands via ODBC?

I suppose that there is a system table where we can search the name of
databases in the server or something like this.

Thanks.
César.
Matej JuracRe: List of Databases in Postgresql.
on Wed, 02 Nov 2016 08:15:56 +0100
Look at this post:

http://dba.stackexchange.com/questions/1285/how-do-i-list-all-databases-and-tables-using-psql

SELECT datname FROM pg_database
WHERE datistemplate = false;

This lists tables in the current database

SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name;

Mind that, even if it lists you database name, depending on SQL user
privilieges you are not always allowed to connect to it.




César Calvo <ccalvoc@telefonica.net> wrote in message
news:4341fcb4$5870e7ef$eacfd@news.alaska-software.com...
>Hi,
>
>I got it with SqlExpress
>
>PROCEDURE PROCESO()
>LOCAL cSIP, oConStr, cConStr, oCon, cSql, oCur, oStmt, dbQuery, cCon, oSes, 
>nCol, A, B
>
>// Conecta con PostGreSql
>
>cConStr := "Driver={Advantage StreamlineSQL ODBC};DataDirectory=" + 
>trim(cDirDB);CharSet=OEM;MemoBlockSize=64;MaxTableCloseCache=20" + ;
>              
";DefaultType=FoxPro;Rows=False;AdvantageLocking=ON;Locking=Record;ServerTypes=2;TrimTrailingSpaces=False;RightsChecking=OFF;"
>
>oCon := SQLConnection():new()
>
>IF oCon:DriverConnect(nil,cConStr)
>
>   Infobox("Conectado")
>
>   cSql := "SELECT * FROM pg_database ORDER BY datname"
>
>   oCur := oCon:Cursor(cSql)
>
>   IF oCur:Seek("dbftid")
>      Infobox("Existe")
>      ELSE
>      Infobox("No Existe")
>   ENDIF
>
>
>"César Calvo"  escribió en el mensaje de 
>noticias:c899c23$73221571$e74d8@news.alaska-software.com...
>
>Hello Friends.
>
>Does anybody knows the way for know if a database exists in postgresql with
>SQL Commands via ODBC?
>
>I suppose that there is a system table where we can search the name of
>databases in the server or something like this.
>
>Thanks.
>César.