PostgreSQL Funzioni

Note

Nota:

Not all functions are supported by all builds. It depends on your libpq (The PostgreSQL C client library) version and how libpq is compiled. If PHP PostgreSQL extensions are missing, then it is because your libpq version does not support them.

Nota:

Most PostgreSQL functions accept connection as the optional first parameter. If it is not provided, the last opened connection is used. If it doesn't exist, functions return false.

Nota:

PostgreSQL automatically folds all identifiers (e.g. table/column names) to lower-case values at object creation time and at query time. To force the use of mixed or upper case identifiers, you must escape the identifier using double quotes ("").

Nota:

PostgreSQL does not have special commands for fetching database schema information (eg. all the tables in the current database). Instead, there is a standard schema named information_schema containing system views with all the necessary information, in an easily queryable form. See the » PostgreSQL Documentation for full details.

Indice dei contenuti

  • pg_affected_rows β€” Restituisce il numero delle tuple coinvolte dall'ultimo comando
  • pg_cancel_query β€” Annulla una query asincrona
  • pg_client_encoding β€” Restituisce la codifica caratteri del client
  • pg_close β€” Chiude una connessione PostgreSQL
  • pg_connect β€” Stabilisce una connessione PostgreSQL
  • pg_connect_poll β€” Poll the status of an in-progress asynchronous PostgreSQL connection attempt
  • pg_connection_busy β€” Riferisce se una connessione Γ¨ occupata o meno
  • pg_connection_reset β€” Rpristina la connessione (riconnette)
  • pg_connection_status β€” Restituisce lo stato di una connessione
  • pg_consume_input β€” Reads input on the connection
  • pg_convert β€” Converte i valori di un array associativo in una forma compatibile con i comandi SQL.
  • pg_copy_from β€” Inserisce le tuple in una tabella prendendole da un array
  • pg_copy_to β€” Copia una tabella in un array
  • pg_dbname β€” Restituisce il nome del database
  • pg_delete β€” Cancella le tuple.
  • pg_end_copy β€” Esegue una sincronizzazione con il backend PostgreSQL
  • pg_escape_bytea β€” Aggiunge le sequenze di escape ai dati binari nel tipo bytea
  • pg_escape_identifier β€” Escape an identifier for insertion into a text field
  • pg_escape_literal β€” Escape a literal for insertion into a text field
  • pg_escape_string β€” Aggiunge le sequenze di escape nei tipi text/char
  • pg_execute β€” Sends a request to execute a prepared statement with given parameters, and waits for the result
  • pg_fetch_all β€” Carica tutte le tuple in un array
  • pg_fetch_all_columns β€” Fetches all rows in a particular result column as an array
  • pg_fetch_array β€” Carica una tupla in un array
  • pg_fetch_assoc β€” Recupera una riga come array associativo
  • pg_fetch_object β€” Carica una tupla in un oggetto
  • pg_fetch_result β€” Restituisce i valori da una risorsa di risultato
  • pg_fetch_row β€” Carica una tupla in un array
  • pg_field_is_null β€” Verifica se un campo Γ¨ null
  • pg_field_name β€” Restituisce il nome di un campo
  • pg_field_num β€” Restituisce la posizione del campo specificato
  • pg_field_prtlen β€” Restituisce la lunghezza "stampabile" di un valore
  • pg_field_size β€” Restituisce la reale dimensione di memorizzazione del campo
  • pg_field_table β€” Returns the name or oid of the tables field
  • pg_field_type β€” Restituisce il nome del tipo del campo specificato
  • pg_field_type_oid β€” Returns the type ID (OID) for the corresponding field number
  • pg_flush β€” Flush outbound query data on the connection
  • pg_free_result β€” Libera la memoria allocata per i risultati
  • pg_get_notify β€” Ottiene il messaggio SQL NOTIFY
  • pg_get_pid β€” Ottiene l'ID del processo del backend
  • pg_get_result β€” Recupera i risultati di una query asincrona
  • pg_host β€” Restituisce il nome dell'host associato alla connessione
  • pg_insert β€” Inserisce un array in una tabella.
  • pg_last_error β€” Restituisce l'ultimo messaggio d'errore di una connessione
  • pg_last_notice β€” Restituisce l'ultimo messaggio di notifica dal server PostgreSQL
  • pg_last_oid β€” Restituisce l'oid dell'ultimo oggetto
  • pg_lo_close β€” Chiude un large object
  • pg_lo_create β€” Crea un large object
  • pg_lo_export β€” Esporta un large object salvandolo su un file
  • pg_lo_import β€” Importa un large object da un file
  • pg_lo_open β€” Apre un large object
  • pg_lo_read β€” Legge un large object
  • pg_lo_read_all β€” Legge interamente un large object e lo manda direttamente al browser
  • pg_lo_seek β€” Ricerca la posizione di un large object
  • pg_lo_tell β€” Restituisce la posizione attuale in un large object
  • pg_lo_truncate β€” Truncates a large object
  • pg_lo_unlink β€” Cancella un large object
  • pg_lo_write β€” Scrive un large object
  • pg_meta_data β€” Ottiene la definizione di una tabella.
  • pg_num_fields β€” Restituisce il numero di campi
  • pg_num_rows β€” Restituiscein numero di tuple
  • pg_options β€” Estrae le opzioni associate alla connessione
  • pg_parameter_status β€” Looks up a current parameter setting of the server
  • pg_pconnect β€” Open a persistent PostgreSQL connection
  • pg_ping β€” Effettua il ping alla connessione del database
  • pg_port β€” Restituisce il numero di porta associato alla connessione
  • pg_prepare β€” Submits a request to the server to create a prepared statement with the given parameters, and waits for completion
  • pg_put_line β€” Invia una stringa terminata da NULL al backend PostgreSQL
  • pg_query β€” Esegue una query
  • pg_query_params β€” Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text
  • pg_result_error β€” Restituisce i messaggio di errore associato al risultato
  • pg_result_error_field β€” Returns an individual field of an error report
  • pg_result_memory_size β€” Returns the amount of memory allocated for a query result
  • pg_result_seek β€” Imposta l'offset di riga interno nella risorsa risultato
  • pg_result_status β€” Recupera lo stato del risultato di una query
  • pg_select β€” Seleziona delle tuple.
  • pg_send_execute β€” Sends a request to execute a prepared statement with given parameters, without waiting for the result(s)
  • pg_send_prepare β€” Sends a request to create a prepared statement with the given parameters, without waiting for completion
  • pg_send_query β€” Invia una query in modo asincrono
  • pg_send_query_params β€” Submits a command and separate parameters to the server without waiting for the result(s)
  • pg_set_chunked_rows_size β€” Set the query results to be retrieved in chunk mode
  • pg_set_client_encoding β€” Imposta la codifica del client
  • pg_set_error_context_visibility β€” Determines the visibility of the context's error messages returned by pg_last_error and pg_result_error
  • pg_set_error_verbosity β€” Determines the verbosity of messages returned by pg_last_error and pg_result_error
  • pg_socket β€” Get a read only handle to the socket underlying a PostgreSQL connection
  • pg_trace β€” iAbilita il tracciamento di una connessione PostgreSQL
  • pg_transaction_status β€” Returns the current in-transaction status of the server
  • pg_tty β€” Restituisce il nome della tty associata alla connessione
  • pg_unescape_bytea β€” Rimuove i caratteri di escape in modo binario per il tipo bytea
  • pg_untrace β€” Disabilita il tracciamento di una connessione PostgreSQL
  • pg_update β€” Modifica le tuple della tabella
  • pg_version β€” Returns an array with client, protocol and server version (when available)
οΌ‹add a note

User Contributed Notes 3 notes

up
6
Tony Murray ΒΆ
14 years ago
A simple conversion for 1D PostgreSQL array data:

// =====
//Example #1 (An array of IP addresses):
<?php
  $pgsqlArr = '{192.168.1.1,10.1.1.1}';

  preg_match('/^{(.*)}$/', $pgsqlArr, $matches);
  $phpArr = str_getcsv($matches[1]);

  print_r($phpArr);
}
// Output:
// Array
// (
//    [0] => 192.168.1.1
//    [1] => 10.1.1.1
// )
// =====

// =====
// Example #2 (An array of strings including spaces and commas):
<?php
  $pgsqlArr = '{string1,string2,"string,3","string 4"}';

  preg_match('/^{(.*)}$/', $pgsqlArr, $matches);
  $phpArr = str_getcsv($matches[1]);

  print_r($phpArr);
}
// Output:
// Array
// (
//    [0] => string1
//    [1] => string2
//    [2] => string,3
//    [3] => string 4
// )
// =====
up
3
abondi at ijk dot it ΒΆ
22 years ago
I've found another function to mimic the following mysql list tables function (http://www.php.net/manual/en/function.mysql-list-tables.php) that's more useful for my target:

function pg_list_tables() {
      $sql = "SELECT a.relname AS Name
          FROM pg_class a, pg_user b
          WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'
          AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner
          AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
      return(pg_query($conn, $sql));
}
up
1
daniel at bichara dot com dot br ΒΆ
23 years ago
Running RedHat Linux and Apache with suexec enabled you must include pgsql.so on each .php file using dl("pgsql.so") and remove "extension=pgsql.so" from php.ini, otherwise Apache (httpd) will not start.