| From: | Juan Rodrigo Alejandro Burgos Mella <rodrigoburgosmella(at)gmail(dot)com> |
|---|---|
| To: | Igor Korot <ikorot01(at)gmail(dot)com> |
| Cc: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: libpq analog of \c |
| Date: | 2026-10-05 20:09:02 |
| Message-ID: | CAHbZ42xNjUmtkhGptghGa3OsLQSFU8J+En271+CBZN_XRYCrwQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
It is entirely possible; multiple connections can be made simultaneously,
but obviously it will depend on the resources of the server where the
binary is running.
here's an example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
EXEC SQL BEGIN DECLARE SECTION;
char conn_str1[256], host1[30], port1[30], ddbb1[30], user1[30],
pass1[30];
char conn_str2[256], host2[30], port2[30], ddbb2[30], user2[30],
pass2[30];
char dbname[100];
EXEC SQL END DECLARE SECTION;
strcpy(host1,"server1.instucion.com");
strcpy(port1,"5433");
strcpy(ddbb1,"ddbb_prod");
strcpy(user1,"user1conect");
strcpy(pass1,"c1d44n");
sprintf(conn_str1,"%s(at)%s:%s", ddbb1, host1, port1);
EXEC SQL CONNECT TO :conn_str1 AS conn1 USER :user1 USING :pass1;
if (sqlca.sqlcode != 0) {
printf("Error conectando a ddbb1: %s\n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
strcpy(host2,"10.91.124.18");
strcpy(port2,"5432");
strcpy(ddbb2,"ddbb_dev");
strcpy(user2,"develop1");
strcpy(pass2,"xcc134q3_#aw");
sprintf(conn_str2,"%s(at)%s:%s", ddbb2, host2, port2);
EXEC SQL CONNECT TO :conn_str2 AS conn2 USER :user2 USING :pass2;
if (sqlca.sqlcode != 0) {
printf("Error conectando a ddbb2: %s\n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
EXEC SQL AT conn1 SELECT current_database() INTO :dbname;
if (sqlca.sqlcode != 0) {
printf("Error SELECT en ddbb1: %s\n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
printf("DDBB 1: [%s]\n", dbname);
EXEC SQL AT conn2 SELECT current_database() INTO :dbname;
if (sqlca.sqlcode != 0) {
printf("Error SELECT en ddbb2: %s\n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
printf("DDBB2 : [%s]\n", dbname);
EXEC SQL DISCONNECT conn1;
EXEC SQL DISCONNECT conn2;
return 0;
}
Atte.
JRBM
El lun, 5 oct 2026 a las 1:11, Igor Korot (<ikorot01(at)gmail(dot)com>) escribió:
> Hi,
> What do issue in the libpq interface to
> select the current database?
>
> Thank you.
>
>
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Thiemo Kellner | 2026-10-06 06:02:08 | Re: Why is materialized view creation a "security-restricted operation"? |
| Previous Message | Igor Korot | 2026-10-05 15:55:15 | Re: libpq analog of \c |