Re: [GENERAL] return two elements

2005-06-06 Thread Franco Bruno Borghesi
You could use your own type, since it seems you know what values you'll be storing there. You can create it like this: CREATE TYPE MyResult AS ( dt_inici DATE, dt_fi DATE ); Then you must change your functions as follows: CREATE OR REPLACE FUNCTION test1() RETURNS MyResult AS ' decl

Re: [GENERAL] return two elements

2005-06-06 Thread Franco Bruno Borghesi
You could use your own type, since it seems you know what values you'll be storing there. You can create it like this: CREATE TYPE MyResult AS ( dt_inici DATE, dt_fi DATE ); Then you must change your functions as follows: CREATE OR REPLACE FUNCTION test1() RETURNS MyResult AS ' decl

Re: [GENERAL] starting postgresql with pgsql password - workarounds?

2005-05-20 Thread Franco Bruno Borghesi
ot;postgresql_command stop"restart_cmd="postgresql_command restart" reload_cmd="postgresql_command reload"status_cmd="postgresql_command status"initdb_cmd="postgresql_initdb"postgresql_command(){su -l ${postgresql_user} -c "exec ${comman

Re: [GENERAL] starting postgresql with pgsql password - workarounds?

2005-05-20 Thread Franco Bruno Borghesi
This is not a PostgreSQL problem, it's the script you are using for startup that has some problem. The pg_hba method is for connection stablishment. PostgreSQL will start no matter what you put there. Startup scripts are usually run as root, and postgresql script should su to the postgresql user t

Re: [GENERAL] Ayuda con postgresql

2005-05-19 Thread Franco Bruno Borghesi
Si necesitás una lista en español, podés ir a http://archives.postgresql.org/pgsql-es-ayuda y suscribirte, los suscriptores de esta lista hablan inglés y no te va a resultar fácil conseguir ayuda :( El tipo de datos que buscas se llama SERIAL (http://www.postgresql.org/docs/8.0/interactive/datatyp

Re: [GENERAL] Disabling Triggers

2005-05-11 Thread Franco Bruno Borghesi
You could add a TIMESTAMP field on the three tables (lets call it last_change), and modify your triggers to update this value every time a row is updated. Then your trigger should update the boolean fields with the boolean value of the row with the max(last_change) in the three tables, only if the

Re: [GENERAL] sequence values question

2005-05-10 Thread Franco Bruno Borghesi
just obtain the next value from the sequence first, then do the insert: CREATE OR REPLACE FUNCTION insert_row(text) returns text language plpgsql AS $$ DECLARE   vdesc alias for $1;   new_id INTEGER; BEGIN     SELECT nextval('sequence_name_here') INTO new_id; INSERT INTO productos (id,

Re: [GENERAL] Howto prevent write based on date

2005-05-05 Thread Franco Bruno Borghesi
You could write a trigger like this: CREATE OR REPLACE FUNCTION checkDate() RETURNS TRIGGER LANGUAGE 'plpgsql' AS ' DECLARE limitDate DATE DEFAULT current_date-''1 year''::INTERVAL; BEGIN IF (OLD.date<=limitDate) THEN RAISE EXCEPTION ''Cannot change record.''; END IF; RETURN NEW; END; '; C

Re: [GENERAL] Sorting by constant values

2005-05-03 Thread Franco Bruno Borghesi
You can order by conditions, lets say column='Unit'. The evaluation of a conditions will give you 't' or 'f', and alfabetically 'f' < 't'... you should use DESC to get the matches first. So, it would be more or less like this: ORDER BY    column='Unit' DESC,    column='Exterior' DESC,    column='C

Re: [GENERAL] Date addition/subtraction

2005-05-03 Thread Franco Bruno Borghesi
It's easy. You have to know that INTERVAL data type exist, so: SELECT current_date - '30 days'::interval SELECT current_timestamp - '1 hour'::interval 2005/5/3, Craig Bryden <[EMAIL PROTECTED]>: HiHow in postgres can I do date/time subtraction or addition.e.g. If I want to get today's date - 30 d

Re: [GENERAL] sub-query question

2004-11-12 Thread Franco Bruno Borghesi
something == otherthing is a boolean expression, you are asking the database to compare both values, u.color_id is not equal c.color_name, that's why you get 'f'. I guess that you want to replace the color_id from users by the corresponding color_name from colors: SELECT c.color_name, u.nam

Re: [GENERAL] Last value inserted

2004-11-11 Thread Franco Bruno Borghesi
I think the best way would be not to use a SERIAL field, but an INTEGER field and a sequence: CREATE SEQUENCE parent_seq; CREATE TABLE parent(id INTEGER, descrip CHAR(50)); So when you want to insert on the parent table, you obtain the next value from the sequence and then you insert in the pare

Re: [GENERAL] Mass Import/Generate PKs

2004-11-06 Thread Franco Bruno Borghesi
I've tested it, and the SERIAL type populates the column when you add it On Sat, 2004-11-06 at 18:56, Ed L. wrote: On Saturday November 6 2004 2:13, Franco Bruno Borghesi wrote: > the simplest way to do it seems to be adding a SERIAL column to your > table, and then adding a

Re: [GENERAL] Mass Import/Generate PKs

2004-11-06 Thread Franco Bruno Borghesi
the simplest way to do it seems to be adding a SERIAL column to your table, and then adding a primary key constraint: 1)insert data into table 2)ALTER TABLE ADD id SERIAL; 3)ALTER TABLE ADD CONSTRAINT _pk PRIMARY KEY (id); you can check the docs for the SERIAL type: http://www.postgresql.or

Re: [GENERAL] Number of months

2004-11-03 Thread Franco Bruno Borghesi
You could create your own function for the conversion, something like: CREATE OR REPLACE FUNCTION interval2Months(INTERVAL) RETURNS INTEGER LANGUAGE 'sql' IMMUTABLE AS ' SELECT CAST(extract(YEAR FROM $1) * 12 + extract (MONTH FROM $1) AS INTEGER); '; you call it doing SELECT interval2Months(

Re: [GENERAL] ON DELETE trigger blocks delete from my table

2004-10-25 Thread Franco Bruno Borghesi
I've made a test case, and setting the trigger BEFORE DELETE doesn't delete the rows from the table (but it does execute the trigger, and it does insert the rows in the audit table), I dont' know why . Anyway, setting the trigger AFTER DELETE works ok. On Mon, 2004-10-25 at 15:56, Naeem Bari

Re: [GENERAL] Postgres update with self join

2004-08-10 Thread Franco Bruno Borghesi
This is the way you do it in postgreSQL: UPDATE    test SET    code=T2.code FROM    test T2 WHERE    test.code=0 AND    test.master=T2.name; you need to specify the join condition in the WHERE clause. On Tue, 2004-08-10 at 00:34, Igor Kryltsov wrote: Hi, If you can help me to correct my

Re: [GENERAL] enumerated type..

2004-07-19 Thread Franco Bruno Borghesi
CREATE DOMAIN is the answer: CREATE DOMAIN mytype AS INT2 CHECK(VALUE>=1 AND VALUE<=6); On Mon, 2004-07-19 at 10:43, [EMAIL PROTECTED] wrote: hi, Is it possible in Postgre to have enum type, so that later table fileld get values from 1-6 (saving space) 1 - statex 2 - stateY 3 - stateZ so

Re: [GENERAL] Error in postgreSQL

2004-07-07 Thread Franco Bruno Borghesi
you should check the logs, when postmaster dies right after starting it always leaves a helpfull message there. On Wed, 2004-07-07 at 10:09, José Augusto Tovar wrote: Hi all, I´m using postgreSQL in WinME and i had a very strange problem. When i start the postgres the process postmaster sta

Re: [GENERAL] retrieving parts of a resultset

2004-02-06 Thread Franco Bruno Borghesi
I think you should use a cursor; you declare it, and then you fetch the rows as you need them. On Fri, 2004-02-06 at 14:04, Christoffer Gurell wrote: I want to create a program which displays large tables and makes this possible over a slow connection. The problem is that when i do a PQexec t

Re: [GENERAL] newbie question... how do I get table structure?

2004-02-06 Thread Franco Bruno Borghesi
that's great, I didn't know about the information schema... guess I never read the 'what's new' document On Fri, 2004-02-06 at 13:15, Tom Lane wrote: Franco Bruno Borghesi <[EMAIL PROTECTED]> writes: > Does anyone know if the ansi sql standard defines a

Re: [GENERAL] Getting table attributes

2004-02-06 Thread Franco Bruno Borghesi
this query will list every table (with its attributes) in the "public" schema. You could alter the where clause to add more schemas (maybe using IN): SELECT N.nspname, C.relname, A.attname, pg_catalog.format_type(a.atttypid, a.atttypmod) AS typeName FROM pg_class C, pg_namespace N, pg_attribut

Re: [GENERAL] newbie question... how do I get table structure?

2004-02-06 Thread Franco Bruno Borghesi
this should work (don't forget to replace !!!): SELECT A.attname, pg_catalog.format_type(a.atttypid, a.atttypmod) AS typeName FROM pg_class C, pg_attribute A, pg_type T WHERE C.relname ILIKE '' AND (C.oid=A.attrelid) AND (T.oid=A.atttypid) AND (A.attnum>0) AND (NOT A.attisd

Re: [GENERAL] max_fsm_pages

2003-12-08 Thread Franco Bruno Borghesi
I've read this message, and tryed to apply this changes to my own database. sapiens=# vacuum verbose; ... INFO:  free space map: 1 relations, 39 pages stored; 48 total pages needed DETAIL:  Allocated FSM size: 1000 relations + 3 pages = 237 kB shared memory. 1 relation and 48 pages seems

Re: [GENERAL] pg_clog problems

2003-11-20 Thread Franco Bruno Borghesi
don't worry!! it's just a cygwin installation for a demostration application for the sales team. Real application runs on bsd On Thu, 2003-11-20 at 11:23, Alvaro Herrera Munoz wrote: On Thu, Nov 20, 2003 at 10:48:08AM -0300, Franco Bruno Borghesi wrote: > The file was there, b

Re: [GENERAL] Is it possible find a size of a table

2003-11-20 Thread Franco Bruno Borghesi
you need to install contrib/dbsize. Then you can do: SELECT relation_size('myTable'); On Thu, 2003-11-20 at 02:30, K. Deepa wrote: Hi All, Is it possible find the size of a pgsql table. TIA signature.asc Description: This is a digitally signed message part

Re: [GENERAL] pg_clog problems

2003-11-20 Thread Franco Bruno Borghesi
01:45:21PM -0300, Franco Bruno Borghesi wrote: > Hi everyone. > > I'm having problems with a database, I get the following errors while > accesing it (from my application and from pg_dump) > > ERROR: Could not access status of transaction 65536 > DETAIL: Could not read from

Re: [GENERAL] Point-in-time data recovery - v.7.4

2003-11-18 Thread Franco Bruno Borghesi
I think it was delayed until 7.5... same for win32 port. Here ir Bruce's message talkin about both topics: http://archives.postgresql.org/pgsql-hackers/2003-07/msg00284.php On Tue, 2003-11-18 at 11:01, Rafael Martinez Guerrero wrote: Hello I am trying to find out when 'Point-in-time data re

Re: [GENERAL] mysql create table -> psql

2003-09-09 Thread Franco Bruno Borghesi
the problem is constraint id PRIMARY (id), it should be constraint id PRIMARY KEY (id). Besides that, you will have problems with '-00-00'... month starts at 1, day starts at 1, and I don't know about year 0. Maybe this field 'time' should be NULLable, or maybe its default value should be

Re: [GENERAL] SRF question

2003-09-08 Thread Franco Bruno Borghesi
yes, parseTypeString() seems to be the way. I've found parseTypeString() in plpgsql.so... would it be ok to call dlopen('plpgsql.so', ...) from my C code to access this function or is there some other method I sould use? thanks tom. On Mon, 2003-09-08 at 12:02, Tom Lane wrote

[GENERAL] SRF question

2003-09-08 Thread Franco Bruno Borghesi
Hi everyone. I need to create a C function that returns a row, and the type of this row must be the same of a type that I've created using CREATE TYPE. I've seen the function: TupleDesc TypeGetTupleDesc(Oid typeoid, List *colaliases) but I don't understand two things: 1)I just know the name

[GENERAL] C functions

2003-09-05 Thread Franco Bruno Borghesi
Hi guys! I need to migrate some plpgsql functions I have to C language. These functions execute queries and process the results inside, and some of them return records... I've been reading the documentation, but I would like any of you to tell me where can I find some examples of these kind o

Re: [GENERAL] table constraints and performance

2003-08-26 Thread Franco Bruno Borghesi
Besides the performance issues, I think it's correct to detect refreshes before sending data to the database. In our applications, we ignore refreshes from the begining. We do it by sending a serial number, which we keep on a session variable. Every time we send a page to a client, we increme

Re: [GENERAL] Buglist

2003-08-25 Thread Franco Bruno Borghesi
Initial beta release of plPHP http://www.postgresql.org/news/143.html On Tue, 2003-08-19 at 10:46, David Siebert wrote: I learned MySQL then went on to Postgres. I chose postgres for my in house project just because of the row locking and transactions. Looking back I could have used MySQL.

Re: [GENERAL] How to do?

2003-08-06 Thread Franco Bruno Borghesi
my old brain. >>I will try to by more unequivocal this time :) >> >>Shridhar Daithankar wrote: >> > select oid,name from a; >>I know it, but i have to have not oid's but row numbers :) such like : >> table "test" >> offset | value >>---

Re: [GENERAL] Batch processing

2003-07-29 Thread Franco Bruno Borghesi
Maybe the best option (specialy if you need users to control the jobs) would be to create a table like this: CREATE TABLE batchjobs (    id SERIAL,    sql TEXT NOT NULL,    done BOOLEAN NOT NOOL DEFAULT false ); Then you create a pl/pgsql function that iterates every "undone" record from this

Re: [GENERAL] 0/1 vs true/false

2003-07-23 Thread Franco Bruno Borghesi
and what about boolean attirbutes in where clauses? Is any difference between -SELECT ... WHERE boolean_field and -SELECT ... WHERE boolean_field=true ? On Wed, 2003-07-23 at 11:48, Tom Lane wrote: Franco Bruno Borghesi <[EMAIL PROTECTED]> writes: > This makes me wonder, what

Re: [GENERAL] SELECT @@IDENTITY

2003-06-23 Thread Franco Bruno Borghesi
I always use Steve's method (it's easier), but if you still want to do it in the sql-server way, you can use OIDs to fetch the id of the last INSERTed row. I don't know which programming language you are using, but are some examples: *plpgsql DECLARE    myOid INTEGER;    identity