[SQL] TG_TABLE_NAME as identifier

2008-02-05 Thread Tiziano Slack
Hello everybody! I'm newbie to plpgsql syntax. Can anyone tell where I'm getting wrong? CREATE OR REPLACE FUNCTION tr_audit() RETURNS TRIGGER AS $tr_audit$ BEGIN IF (TG_OP = 'UPDATE') THEN ... NEW.id = nextval(TG_TABLE_NAME || '_id_seq'::regclass); INSERT INTO

Re: [SQL] TG_TABLE_NAME as identifier

2008-02-05 Thread Richard Huxton
Tiziano Slack wrote: Hello everybody! I'm newbie to plpgsql syntax. Can anyone tell where I'm getting wrong? INSERT INTO TG_TABLE_NAME SELECT NEW.*; If you need to build a dynamic query with plpgsql you'll need to assemble it as a string and use EXECUTE. You can use variables in comparison

Re: [SQL] TG_TABLE_NAME as identifier

2008-02-05 Thread Robins Tharakan
Hi, I am not sure if this'd help : 1. Are you sure that the sequence and the tablename have the same name ? [The insert statement is seeing the insert target identifier as a variable] 2. In case you need to run the [INSERT INTO '|| TG_TABLE_NAME ||' SELECT NEW.* ] statement you could always use

[SQL] Cast in PG 8.3

2008-02-05 Thread Franklin Haut
Hi all, I´m testing the new version of PostgreSQL in windows plataform but i have a problem. In PG 8.2 Create Table temp (id int4); insert into temp values (1215); insert into temp values (1216); insert into temp values (1217); insert into temp values (1218); insert into temp values (1

Re: [SQL] Cast in PG 8.3

2008-02-05 Thread Jaime Casanova
On Feb 5, 2008 2:22 PM, Franklin Haut <[EMAIL PROTECTED]> wrote: > > > Hi all, > > I´m testing the new version of PostgreSQL in windows plataform but i have a > problem. > > > In PG 8.2 > > Create Table temp (id int4); > insert into temp values (1215); > insert into temp values (1216); > insert int

[SQL] Negative numbers for PK/ID's?

2008-02-05 Thread Steve Midgley
Hi, A while ago on a different SQL platform, I had the idea to use negative numbers as id's for certain system records that I didn't prefer to have interspersed with other records in a table. (For example, we had "template" records which we used to spawn new records, and rather than store the

Re: [SQL] Cast in PG 8.3

2008-02-05 Thread Jaime Casanova
On Feb 5, 2008 2:39 PM, Li, Jingfa <[EMAIL PROTECTED]> wrote: > check the typo -- "ilike" > that's not a typo, it's "case insensitive LIKE" -- regards, Jaime Casanova "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the univers

Re: [SQL] Cast in PG 8.3

2008-02-05 Thread Li, Jingfa
check the typo -- "ilike" -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jaime Casanova Sent: Tuesday, February 05, 2008 11:19 AM To: Franklin Haut Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Cast in PG 8.3 On Feb 5, 2008 2:22 PM, Franklin Haut <[EM

Re: [SQL] Cast in PG 8.3

2008-02-05 Thread Li, Jingfa
the column is an integer, no sense for case sensitive or insensitive... change it to 'like', you'll get what you want. -Original Message- From: Jaime Casanova [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 05, 2008 11:47 AM To: Li, Jingfa Cc: Franklin Haut; pgsql-sql@postgresql.org Su

Re: [SQL] Cast in PG 8.3

2008-02-05 Thread Markus Bertheau
2008/2/6, Jaime Casanova <[EMAIL PROTECTED]>: > did you read the release notes? Obviously he did: > I Know that changing the SQL command to : > SELECT * FROM TEMP WHERE CAST(id AS TEXT) ilike ('%122%'); > work´s but for now isn't possible... :( > > > I Tries create a cast but the function text

Re: [SQL] Cast in PG 8.3

2008-02-05 Thread Tom Lane
Franklin Haut <[EMAIL PROTECTED]> writes: > Create Table temp (id int4); > insert into temp values (1215); > insert into temp values (1216); > insert into temp values (1217); > insert into temp values (1218); > insert into temp values (1219); > insert into temp values (1220); > insert into temp val

Re: [SQL] Negative numbers for PK/ID's?

2008-02-05 Thread Tom Lane
Steve Midgley <[EMAIL PROTECTED]> writes: > I'm wondering if there are any Bad Things that happen if I use negative > integers for primary key values in Postgres (v8.2)? No. regards, tom lane ---(end of broadcast)--- TIP 4:

Re: [SQL] Cast in PG 8.3

2008-02-05 Thread Volkan YAZICI
Franklin Haut <[EMAIL PROTECTED]> writes: > I Tries create a cast but the function text doesn't exist more in PG 8.3 sql-createcast.html tells that "It is normally not necessary to create casts between user-defined types and the standard string types (text, varchar, and char(n)). PostgreSQ

[SQL] Multiple postgresql functions in a single transaction

2008-02-05 Thread Jyoti Seth
Hi, I have two postgresql functions. One function is calling another function for certain value. I want that these two functions work under single transaction so that even if the value gets generated in the second function and the first function that calls the second function fails. Then the value

Re: [SQL] Multiple postgresql functions in a single transaction

2008-02-05 Thread Robins Tharakan
> It can be done, but it depends on how you are generating the value in the > first function. > If you sequences though you may have to take care of reverting it > yourself. > > *Robins* > > > -- Forwarded message -- > From: Jyoti Seth <[EMAIL PROTECTED]> > Date: Feb 6, 2008 11:51 A

Re: [SQL] Multiple postgresql functions in a single transaction

2008-02-05 Thread Jyoti Seth
Thanks. I am not using sequences. I tried an example and it worked. From: Robins Tharakan [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 06, 2008 12:54 PM To: Jyoti Seth Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Multiple postgresql functions in a single transaction It can be

Re: [SQL] Multiple postgresql functions in a single transaction

2008-02-05 Thread sad
Robins Tharakan wrote: > > It can be done, but it depends on how you are generating the value in the > > first function. > > If you sequences though you may have to take care of reverting it > > yourself. Sequences had been constructed in this manner not to cause pain for users -- think of it. S