|
| | Run external script in psql
To run a script against a PostgreSQL database from Unix / Linux command prompt do the following:
psql [database name] < [script name]
Otherwise if you are connected to database through psql and want to call an external script you can use \i for example:
testdb=# \i [script name]
| |  More... 03/30/07 | | | | |
|
| | Change PostgreSQL table column
In this example a column type is changed to varchar of size up to 10 characters:
ALTER TABLE [table name] ALTER COLUMN [column name] TYPE VARCHAR(10); | | More... 02/27/07 | | | | |
|
| | How to add a column to PostgreSQL table
Below example adds a new column of type varchar and length 10 characters to a PostgreSQL database table:
psql> ALTER TABLE [table_name] ADD COLUMN [column_name] VARCHAR(10);
You can run it from psql, phpPgAdmin or any other admin tool
| | More... 01/19/07 | | | | |
|
| | How to reset sequence to a specific number
If you need to set a sequence to start from a specific number in PostgreSQL run this command in psql or phpPgAdmin:
alter sequence [sequence_name] restart with 436;
In this particular example the sequence will start from 436. | | More... 11/08/06 | | | | |
|
| | Select nextval from multiple sequences at the same time
Sometimes you may want to get nextval from several sequences at the same time, i.e. if fields are not set to auto increment and you want to run transaction from php script, this will save calls to pg_query and pg_fetch_array. Here's one of the ways to do it in PostgreSQL ... | | More... 08/09/06 | | | | |
|
| | Selecting random record
To select a random record from PostgreSQL table use the following SQL statement:
SELECT col_name
FROM table_name
ORDER BY random()
LIMIT 1;
| | More... 02/16/06 | | | | |
|
|