[SQL] Using functions in SQL statements

2001-08-05 Thread Allan Engelhardt
I would dearly love to do CREATE GROUP foo WITH USER CURRENT_USER; in a script to psql(1), but this does not appear to be supported by the parser. Two questions: 1. Does anybody have a good work-around for this? 2. Is there a document somewhere that says where functions are allowed in SQL

[SQL] Creating foreign key constraint to child table?

2001-08-05 Thread Allan Engelhardt
I would like to create a FOREIGN KEY constraint to an inherited column, like: test=# CREATE TABLE foo(id INTEGER PRIMARY KEY); test=# CREATE TABLE bar() INHERITS (foo); test=# CREATE TABLE baz (bar INTEGER, CONSTRAINT fk_bar FOREIGN KEY (bar) REFERENCES bar(id)); ERROR: UNIQUE c

[SQL] Re: Creating foreign key constraint to child table?

2001-08-05 Thread Allan Engelhardt
I obviously haven't had enough coffee yet... :-) The following script works as expected. drop database test; create database test; \c test create table foo (id integer primary key); create table bar () inherits (foo); create unique index bar_id_idx ON bar(id); create table baz (bar integer,

Re: [SQL] Creating foreign key constraint to child table?

2001-08-05 Thread Stephan Szabo
On Sun, 5 Aug 2001, Allan Engelhardt wrote: > test=# create table baz(bar integer, constraint fk_bar foreign key (bar) >references foo(id)); > NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s) > CREATE > > but this is not exactly what I want: I need to e

[SQL] Re: Creating foreign key constraint to child table?

2001-08-05 Thread Allan Engelhardt
Stephan Szabo wrote: > On Sun, 5 Aug 2001, Allan Engelhardt wrote: [see new example below] > Not that this is related to what you asked about precisely (I saw the > response you made), but the query above also doesn't do what you think > it does right now. It currently makes a reference to onl

Re: [SQL] Creating foreign key constraint to child table?

2001-08-05 Thread Dmitry G. Mastrukov
05 Aug 2001 13:49:22 +0100, Allan Engelhardt > I would like to create a FOREIGN KEY constraint to an inherited column, like: > > test=# CREATE TABLE foo(id INTEGER PRIMARY KEY); > test=# CREATE TABLE bar() INHERITS (foo); > test=# CREATE TABLE baz (bar INTEGER, CONSTRAINT fk_bar

[SQL] Re: Date Time Functions - ANSI SQL ?

2001-08-05 Thread Peter Eisentraut
Gonzo Rock writes: > I'm trying to find a pgSQL source that documents the Non-Standard > pgSQL stuff, the stuff that will break when attempting to execute > against mySQL/Oracle/MSSQLServer etc... While it would be an appreciated effort to create such a document (and we already try to document s

[SQL] Re: Fuzzy matching?

2001-08-05 Thread Peter Eisentraut
Josh Berkus writes: > For many of my programs, it would be extremely useful to have some form > of "fuzzy matching" for VARCHAR fields. For lexical similarity, check out the agrep algorithm. Last I checked the source code wasn't quite Free(tm), but the algorithm was published in an academic wor

[SQL] Inheritance is completely broken [was: Re: Creating foreign key constraint to child table?]

2001-08-05 Thread Allan Engelhardt
Dimitri pointed out (the post does not seem to have appered yet) that you can also do: test=# create table foo(id integer primary key); NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo' CREATE test=# create table bar () inherits (foo);

[SQL] Data type confusion

2001-08-05 Thread Josh Berkus
Tom, Stephan, I'm writing up the date/time FAQ, and I came across some operator behavior that confuses me: If INTERVAL / INTEGER = INTERVAL then why does INTERVAL / INTERVAL = ERROR? Shouldn't INTERVAL / INTERVAL = INTEGER? I'd like to answer this before I finish the FAQ, as it seems inconsis

Re: [SQL] Re: Date Time Functions - ANSI SQL ?

2001-08-05 Thread Josh Berkus
Gonzo, > > I'm trying to find a pgSQL source that documents the Non-Standard > > pgSQL stuff, the stuff that will break when attempting to execute > > against mySQL/Oracle/MSSQLServer etc... Almost anything you port will break MS SQL Server (7.0 and 6.5, anyway). SQL Server is so far off the ANS

[SQL] Re: Data type confusion

2001-08-05 Thread Allan Engelhardt
Josh Berkus wrote: > This is a multi-part MIME message > > --_===97089davinci.ethosmedia.com===_ > Content-Type: text/plain; charset="ISO-8859-1" > Content-Transfer-Encoding: 8bit > > Tom, Stephan, > > I'm writing up the date/time FAQ, and I came across some operator > behavior that confuses

Re: [SQL] Data type confusion

2001-08-05 Thread Tom Lane
"Josh Berkus" <[EMAIL PROTECTED]> writes: > If > INTERVAL / INTEGER = INTERVAL Actually the operator appears to be INTERVAL / FLOAT8. > then why does > INTERVAL / INTERVAL = ERROR? Because no one got around to creating an INTERVAL / INTERVAL operator. There are plenty of such gaps in our operat

Re: [SQL] Data type confusion

2001-08-05 Thread Josh Berkus
Tom, > > then why does > > INTERVAL / INTERVAL = ERROR? > > Because no one got around to creating an INTERVAL / INTERVAL > operator. > There are plenty of such gaps in our operator set... Bummer. If I could "C" then maybe I'd do something about it. > > > Shouldn't > > INTERVAL / INTERVAL = I

Re: [SQL] Re: Data type confusion

2001-08-05 Thread Tom Lane
Allan Engelhardt <[EMAIL PROTECTED]> writes: > I don't think it makes conceptual sense to divide intervals It is kinda bogus, given the underlying semantics of intervals (integer months plus float seconds). The problem already arises for the existing interval * float8 and interval / float8 o

Re: [SQL] Re: Data type confusion

2001-08-05 Thread Peter Eisentraut
Tom Lane writes: > It is kinda bogus, given the underlying semantics of intervals > (integer months plus float seconds). > This is pretty grotty, and AFAIK not documented anywhere --- I found it > out by looking at the C code for these operators. But I'm not sure > how to do better. One day we

Re: [SQL] Re: Data type confusion

2001-08-05 Thread Tom Lane
Peter Eisentraut <[EMAIL PROTECTED]> writes: > One day we will have to accept the fact that months and seconds must not > be mixed, period. You can have year/month intervals or > day/hour/minute/second intervals, not a combination. An interval of '5 > years 3 minutes' has no meaning with the nat

Re: [SQL] Re: Data type confusion

2001-08-05 Thread Peter Eisentraut
Tom Lane writes: > I don't agree --- five years and three minutes is perfectly meaningful. > There are only certain things you can validly do with it, however, and > scaling by a floating-point number isn't one of them, because fractional > months aren't well-defined. But you can, for example, a

Re: [SQL] Re: Data type confusion

2001-08-05 Thread Tom Lane
Peter Eisentraut <[EMAIL PROTECTED]> writes: > but > '2001-08-06 03:03:03' - '2000-08-06 03:03:00' = '365 days 3 seconds' > '2000-08-06 03:03:03' - '1999-08-06 03:03:00' = '366 days 3 seconds' What I said was that timestamp plus or minus interval is well-defined (when "interval" is a multi-part