[SQL] subselects - which is faster?

2003-06-12 Thread Cedar Cox
It's been a while since I've done much SQL.. . I'm wondering which of these two queries is faster (both get the same result)? . Which one is more correct? Does it even matter or are they the same? The first one reads easier to me. . What's the difference between "InitPlan" and "SubPlan"? exp

[SQL] undocumented setval()

2001-08-26 Thread Cedar Cox
When looking through a dump file, I noticed a setval(text, int, bool). What is this? It doesn't appear to be documented. -Cedar ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

[SQL] REFERENCES constraint

2001-08-08 Thread Cedar Cox
Two questions (maybe they are silly..) 1. Can a column reference more than one table? (This assumes you use a single sequence to generate the IDs for both "tbla" and "tblb". I guess you would also have the problem of enforcing a unique index. Say what?! A unique index across multiple tables

Re: [SQL] Calculating the age of a person

2001-05-20 Thread Cedar Cox
Or you could use date_trunc() in the same way as date_part() if you want an interval instead.. SELECT date_trunc('year',age(birth)),* FROM persons LIMIT 1; On Fri, 18 May 2001, [EMAIL PROTECTED] wrote: > You are probably looking for date_part(). > > E.g. > > SELECT date_part('year',age(birt

[SQL] timestamp bug

2001-05-20 Thread Cedar Cox
There appears to be a bug in timestamp/interval addition. It happens in both PG version 7.0.2 and 7.1. There is a duplicate day (2001 Sep 07) and a missing day (2002 Apr 04). I discovered this by accident when I asked the interface I'm writing for a 365 day long calendar.. Interestingly, the

Re: [SQL] select ... for update in plpgsql

2001-04-24 Thread Cedar Cox
'select ... for update' needs to be inside a transaction. plpgsql cannot start or end transactions. 'begin' and 'end' are not transaction statements. (read the docs). -Cedar On Fri, 20 Apr 2001, Jie Liang wrote: > > Hi, > > I have a question about 'select ... for update'; > according to t

Re: [SQL] Timezone conversion

2001-04-24 Thread Cedar Cox
Umm.. define 'it'. (Isn't current_timestamp or now() already a timestamp?) select CURRENT_TIMESTAMP, CURRENT_TIMESTAMP-2*3600; timestamp| ?column? + 2001-04-24 13:06:11+03 | 1981-08-07 I also have a question.. How, for example, would I add

[SQL] pg_dump bug? (7.1)

2001-04-23 Thread Cedar Cox
Well, I finally decided to play around with 7.1. Here's the problem: When I try to run pg_dump I get a segmentation fault. This only seems to happen if the PGDATABASE environment variable is set and I don't supply the database name on the command line. If I unset PGDATABASE, I get a normal e

Re: [SQL] Bug in user management?

2001-04-14 Thread Cedar Cox
While we're on this subject, where is the documentation on pg_shadow? Specifically, what it 'usetrace' for? -Cedar On Fri, 13 Apr 2001, Tom Lane wrote: > =?iso-8859-1?Q?Hans=2DJ=FCrgen=20Sch=F6nig?= <[EMAIL PROTECTED]> writes: > > I have created a user called epi who is not allowed to create

Re: [SQL] Foreign Key between different databases

2001-04-11 Thread Cedar Cox
AFAIK, not easily. There was a post to the hackers list recently with code for a "database connector" function. Using this it may be possible to write your own referential integrity triggers that reference the other database.. maybe not. I didn't look much into the code. There might be someth

Re: [SQL] please help

2001-04-08 Thread Cedar Cox
It would be somewhat (very) useful to have something like this. We were toying with the idea of making some sort of system to figure out if a table is locked or not. In the end we decided to go with executing this asynchronously and after a given timeout ask the user if they would like to wait

Re: [SQL] Double-nesting quotes?

2001-04-08 Thread Cedar Cox
Carefully. :) Try: where_string := ''WHERE client_name ~* '' || s_client || ; (I think I got that right.) The way I do it is to write it first as if I'm not inside a function and not double my single quotes. After I'm done, go back and double all of them.. you're on you own if

Re: [SQL] Need help with EXECUTE function

2001-04-08 Thread Cedar Cox
Attached is the (I think) corrected version.. If you do like I said and cut the number in half you see fairly quickly why it didn't work. I'm sending yours back so you can easily run a diff to see what I did. Let me know if this (attached "cedars") works. -Cedar On Sat, 7 Apr 2001, Josh Berk

Re: [SQL] Casting numeric to text

2001-04-08 Thread Cedar Cox
On Sun, 8 Apr 2001, Peter Eisentraut wrote: > Hans-Jürgen Schönig writes: > > > Is there any possibility to cast numeric to text in Postgres 7.0.3? > > > > shop=# select cast(price as text) from products; > > ERROR: Cannot cast type 'numeric' to 'text' > > Use the to_char() function. When w

Re: [SQL] max( bool )?

2001-04-04 Thread Cedar Cox
On Wed, 4 Apr 2001, Tom Lane wrote: > Cedar Cox <[EMAIL PROTECTED]> writes: > > And I get this notice: > > > NOTICE: PortalHeapMemoryFree: 0x0x824a6e8 not in alloc set! > > NOTICE: Buffer Leak: [059] (freeNext=54, freePrev=58, relname=tblstsc1, > > bl

[SQL] max( bool )?

2001-04-04 Thread Cedar Cox
Question and a problem: I have this query select distinct not exists ( select sc1caption from tblstsc1 where (tblstsc1options.surid like surid || '.%' or surid=tblstsc1options.surid) and surid!=tblstsc1options.surid and sc1caption is not null ) from tblstsc1o

Re: [SQL] Escaping \

2001-03-29 Thread Cedar Cox
> > I've a problem with escaping a \ in a string. > > > > When I enter the query: > > > > SELECT '''\\\''; I get the right result: '\' > > > > But when I try this in a Function: > > > > CREATE FUNCTION sp_tmp() RETURNS varchar(10) > > AS ' > > SELECT ''\\\' AS RESULT' > > LANGUAGE 'sql';

Re: [SQL] Function with now() | time 'now' | etc...

2001-03-29 Thread Cedar Cox
> [EMAIL PROTECTED] writes: > > It doesn't getting different times on each execution. I also tried put > > "timestamp 'now'" insted "now()". What am I doing wrong? > > now() is defined to return the time of the start of the current > transaction. It won't change value inside a transaction

Re: [SQL] Self-Referencing

2001-03-29 Thread Cedar Cox
On Wed, 28 Mar 2001, David Olbersen wrote: > Hello, > > I have a feeling this isn't going to make much sense, but I'm gonig to try > anyway. > > What I'd like to do is be able to refer to an outer-SELECT from an > inner-SELECT. I hope this makes sense. > > I need to be able to refer

Re: [SQL] SELECT ... FOR UPDATE

2001-03-29 Thread Cedar Cox
On Wed, 28 Mar 2001, Marcos Minshew wrote: > I am interested in using the SELECT ... FOR UPDATE feature but it doesn't > work quite the way I had hoped. If there is a better/different way of doing > this please enlighten me. > > If I issue: > > BEGIN; > SELECT * FROM atable WHERE atable.key

Re: [SQL] is it me or trigger side effects

2001-03-26 Thread Cedar Cox
On Mon, 26 Mar 2001, Stephan Szabo wrote: > > > create function updateCat() returns opaque as ' > > declare > > rec record; > > rename new to cat; > > rename old to ct; > > maxlen integer; > > > > begin > > if tg_op = ''INSERT'' and cat.category is null then > >

Re: [SQL] Help

2001-03-26 Thread Cedar Cox
> > Thanks for your valuable information. I tried the > > cron. i typed > >cron -e > > and entereed into the input area. but i don't know how > > to save the cron file. I pressed ctrl+z and came out > > from cron. but i edit the cron file i found nothing on > > it.(i.e using pico filename.)

Re: [SQL] Functions and Triggers

2001-03-26 Thread Cedar Cox
CREATE FUNCTION lastupdated() RETURNS opaque AS ' begin new.last_updated := CURRENT_TIMESTAMP; return new; end; ' LANGUAGE 'plpgsql'; CREATE TRIGGER trigname BEFORE INSERT OR UPDATE on tblname FOR EACH ROW EXECUTE PROCEDURE lastupdated(); Note: you could use now() instead of CURRENT_TIMES

Re: [SQL] Maybe a Bug, maybe bad SQL

2001-03-21 Thread Cedar Cox
> > Why does everyone reply to the person as well as CC to the list when the > > person is on the list anyhow? > > Good question. They get the reply faster by sending it to them and the > list, and if someone later wants to reply only to the poster, they have > the email address right there. A

Re: [SQL] how do I find which ...

2001-03-21 Thread Cedar Cox
On Wed, 21 Mar 2001, datactrl wrote: > I write some functions inPL/pgSQL. If I drop a function B , which is called > by function A, and create function B again, then function A won't work If I recall correctly, this is because function A's "compiled" code refers to the oid of the now non-exist

[SQL] triggered data change violation

2001-03-20 Thread Cedar Cox
Added note: The trigger is a BEFORE trigger. -- Forwarded message -- To: [EMAIL PROTECTED] Date: Tue, 20 Mar 2001 20:43:59 +0200 (IST) Subject: triggered data change violation ERROR: triggered data change violation on relation "tblstsc2options" What is this? It doesn't happ

[SQL] Re: [INTERFACES] pl/pgSQL & transaction

2001-01-23 Thread Cedar Cox
On Thu, 18 Jan 2001, Zolof wrote: > This code doesn't work. I use Begin Work to start a transaction but BEGIN is > a PL/pgSQL command so I have a parse error when executing it. > > CREATE FUNCTION a () RETURNS int4 AS ' > BEGIN >BEGIN WORK; >COMMIT WORK; > return 1; > END; > '