[SQL] update and IN vs. EXISTS

2003-02-01 Thread pginfo
Hi,

I have 2 tables Table1 and Table2.
The PK for Table1 is declared as name.
Table 2 have only 1 field and it is also name ( it is indexed).

I will to update all Table1.filedForUpdate for all rows that exists in
Table2.

In Table1 I have ~ 120 000 rows and in Table2 I have ~ 100 000.

If I execute:
   update Table1 set fieldForUpdate = 1;

it takes ~ 28 sec. I test it only to know how much time will I need for
all rows.

If I try to execute:
   update Table1 set fieldForUpdate = 1 where ID IN (select T2.ID from
Table2);
it is running very slow.

I do not nkow how many time, but I waited ~ 30 min without to get
result.

I tested anoder query:
   update Table1 set fieldForUpdate = 1 where ID IN ( select T1.ID from
Table1 T1 where exists (select * select T2.ID from Table2 where
T1.IDS=T2.IDS ));
and it was running > 30 min ( I do not know how many).

And the last query:
   update Table1 set fieldForUpdate = 1 from Tablet T1 where EXISTS
(select * select T2.ID from Table2 where T1.IDS=T2.IDS );
and it was also > 30 min.

How can I speed up this update?

I have executed vacuum and vacuum full analyze.

redards,
ivan.





---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



[SQL] vacuum and serial primary keys

2003-02-01 Thread Carmen Marincu
Hello -

I am using Postgresql 7.1.3 and I have deleted 3000 rows from a table
(with DELETE).
Than I used vacuum  to actually delete the rows markes as deleted
by the DELETE command..
The trouble is that the "counter" for the serial primary key (ID field)
wasn't reset. So now althought I have only 2 rows in my table they have
the ID 3001 and 3002.

Is this normal ? If not could someone please explain me how could  I reset
the "counter" to ignore the deleted rows ?

Thank you very much
Carmen



---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [SQL] vacuum and serial primary keys

2003-02-01 Thread D'Arcy J.M. Cain
On Saturday 01 February 2003 07:45, Carmen Marincu wrote:
> I am using Postgresql 7.1.3 and I have deleted 3000 rows from a table
> (with DELETE).
> Than I used vacuum  to actually delete the rows markes as deleted
> by the DELETE command..
> The trouble is that the "counter" for the serial primary key (ID field)
> wasn't reset. So now althought I have only 2 rows in my table they have
> the ID 3001 and 3002.
>
> Is this normal ? If not could someone please explain me how could  I reset
> the "counter" to ignore the deleted rows ?

It is very normal.  The last thing you need is a database engine that changes 
your primary key without an explicit command to do so.  In fact, sometimes I 
think that the database should enforce the rule that primary keys are 
immutable and not even allow it explicitely.  Perhaps a configuration option.

-- 
D'Arcy J.M. Cain|  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [SQL] update and IN vs. EXISTS

2003-02-01 Thread Bruno Wolff III
On Sat, Feb 01, 2003 at 12:40:00 +0100,
  pginfo <[EMAIL PROTECTED]> wrote:
> 
> If I try to execute:
>update Table1 set fieldForUpdate = 1 where ID IN (select T2.ID from
> Table2);
> it is running very slow.

You might try:
  update Table1 set fieldForUpdate = 1 from Table2 where Table1.id = Table2.id;

This uses a nonstandard postgres extension and may not be portable, if that
is a concern.

INs are being speeded up in 7.4, so the original form might work a lot better
in the next release.

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [SQL] update and IN vs. EXISTS

2003-02-01 Thread pginfo


Bruno Wolff III wrote:

> On Sat, Feb 01, 2003 at 12:40:00 +0100,
>   pginfo <[EMAIL PROTECTED]> wrote:
> >
> > If I try to execute:
> >update Table1 set fieldForUpdate = 1 where ID IN (select T2.ID from
> > Table2);
> > it is running very slow.
>
> You might try:
>   update Table1 set fieldForUpdate = 1 from Table2 where Table1.id = Table2.id;
>

It is great.It takes 122 sec.
With IN it takes 8000 sec.

> This uses a nonstandard postgres extension and may not be portable, if that
> is a concern.
>

How to resolve the problem with the standart?regards,
iavn.

> INs are being speeded up in 7.4, so the original form might work a lot better
> in the next release.
>
> ---(end of broadcast)---
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org




---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



Re: [SQL] Controlling access to Sequences

2003-02-01 Thread Ross J. Reedstrom
On Sat, Feb 01, 2003 at 12:39:50AM -0600, Bruno Wolff III wrote:
> On Fri, Jan 31, 2003 at 23:47:27 +1100,
>   Matthew Horoschun <[EMAIL PROTECTED]> wrote:
> > 
> > Is there any effective method for controlling access to a SEQUENCE? or 
> > should I do something like in the view:
> 
> You can limit access to nextval by only allowing access through a user
> defined function that runs as the definer. If you only want them to use
> the function when doing an insert into a specific table, then I am not
> sure if you can do this easily. At worst you could write a function
> that does the insert.

Define your 'suid_nextval()' as Bruno suggests, then instead of using the
'serial' convience type, define your own that uses your function as the
default, rather than nextval().

Ross

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



[SQL] extracting constraints from schema

2003-02-01 Thread Agnieszka Rutkowska
Hi,

I was just wondering whether you happen to know how to extract what the
table and column constraints are using jdbc?
The API provides methods for extracting meta data on the table names,
column names, primary and foreigh keys as well as column types and sizes.
What about extracting constraints such as

salary  realCHECK (salary >= 1)

?
It is possible to obtain the column name 'salary' as well as its types as
being 'real' but how about the CHECK condition?? Can it be done using
jdbc?

Thanks for your time and help
Agnes


---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



[SQL] returning table from a function

2003-02-01 Thread Seethalakshmi VB



Hi
How to return a user created table from a 
function?
 


Re: [SQL] Creating tables from within functions

2003-02-01 Thread Sondaar Roelof
Hello,

Try this:
CREATE FUNCTION _testcreate () RETURNS text AS '
BEGIN
CREATE TABLE switch_table2 (switch_id varchar(32),
selection_name varchar(100));
RETURN ''true'';
END;
' language 'plpgsql';

SELECT _testcreate();

Result:
snlsor=# SELECT _testcreate();
 _testcreate
-
 true
(1 row)

me=# \d
 List of relations
  Name  |   Type   | Owner
+--+
 switch_table2  | table| me

> -Original Message-
> From: Seethalakshmi VB [SMTP:[EMAIL PROTECTED]]
> Sent: vrijdag 24 januari 2003 09:37
> To:   [EMAIL PROTECTED]
> Subject:  [SQL] Creating tables from within functions 
> 
> Is it possible to issue a CREATE TABLE statement from inside of a
> PostgreSQL
> function?  If not, then how about from within a PL/pgSQL function?  I have
> tried a lot of different permutations but can't seem to get it to compile
> and/or run cleanly.  For example, consider:
> 
>   CREATE FUNCTION _testcreate () RETURNS text AS '
>   BEGIN
>   CREATE TABLE switch_table2 (switch_id varchar(32),
> selection_name varchar(100));
>   end;
>   ' language 'plpgsql';
> 
> What is wrong with this?  What type should be returned?  Or perhaps it is
> simply not possible to create a table from within a function?
> 
> Please give me the reply soon as possible
> Thanks!
> 
> ---(end of broadcast)---
> TIP 4: Don't 'kill -9' the postmaster

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [SQL] double linked list

2003-02-01 Thread --CELKO--
>> The table at hand is more a kind of a collection of graphs where I
want to find all possible paths between a given starting point and a
given end point. <<

For the reachabiity index of a general graph, you need Warshal's
algorithm.

Let V = number of nodes in the graph
Let A[i,j] be the adjacency matrix for the undirected graph

FOR j:= 1 TO V
 DO FOR i:= 1 TO V
 DO IF A[i,j] = 1
THEN FOR k := 1 TO V
  DO IF A[j,k]] = 1
 THEN A[i,k]] := 1;

You can also do a summation to get the length of the path from i to j.
You can concatenate names of the nodes into a string that gives the
path, etc.

Her is a first attempt at some SQL; I am sure it can be done better

CREATE TABLE Graph 
(i CHAR(2) NOT NULL,
 j CHAR(2) NOT NULL,
 flag CHAR(1) NOT NULL DEFAULT 'n'
   CHECK (flag IN ('n', 'y')),
 PRIMARY KEY (i,j));

INSERT INTO Graph (i, j, flag)
 SELECT DISTINCT G1.i, G2.j, 'y'
   FROM Graph AS G1, Graph AS G1
  WHERE G1.i <> G2.j
AND EXISTS
(SELECT *
   FROM Graph AS G3
  WHERE G3.i = G1.j
AND G3.j = G2.i)
AND NOT EXISTS
(SELECT *
   FROM Graph AS G3
  WHERE (G3.i = G1.i AND G3.j = G1.j))
 OR (G3.i = G2.i AND G3.j = G2.j));

You wll have to run this statement until the size of Graph does not
change -- no new rows are being added.

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



[SQL] COPY use in function with variable file name

2003-02-01 Thread Sondaar Roelof
Hello,

I can't figure out how to make this work, or is not possible?

In a function i would like to read a file.
The file name is determined by a value from a table.
However the COPY statement does not to accept this?
I tried various forms of adding (single)-quotes but no luck.

Anyone any ideas?

Function:
CREATE FUNCTION dnsdhcp_dns_raw()
/* Fill table dns_raw with dns data */
RETURNS integer AS '
DECLARE
r   RECORD;
ntw TEXT;
BEGIN
/* Do for all domain names */
FOR r IN SELECT domain FROM network
WHERE position(''n'' IN use) > 0 and ipaddress != ''127.0.0.0/24''
LOOP
ntw := ''/tmp/db.'' || r.domain;
DELETE FROM dns_raw; /* Clear table */
RAISE NOTICE ''Network: %'', ntw;
COPY dns_raw FROM ntw DELIMITERS ''~''; /* Get the data */
END LOOP;
RETURN 0;
END;'
LANGUAGE 'plpgsql';

Result:
id=# select dnsdhcp_dns_raw();
NOTICE:  Network: /tmp/db.test.dummy.com
ERROR:  parser: parse error at or near "$1"

Tables:
CREATE TABLE dns_raw (
dataTEXT
);

  Table "network"
 Attribute  |  Type   |  Modifier
+-+-
---
 id | integer | not null default
nextval('"network_id_seq"'::text)
 ipaddress  | cidr| not null
 domain | text| not null
 email  | text| not null
 location   | text| not null default 'l'
 use| text| not null default 's'
 ttl| text| not null default '3h'
 serial | integer | not null default 1
 refresh| text| not null default '3h'
 retry  | text| not null default '1h'
 expire | text| not null default '1w'
 cachettl   | text| not null default '1d'
 lease_time_default | integer | not null default 86400
 lease_time_minimum | integer | not null default 0
 lease_time_maximum | integer | not null default 0
 client_updates | text| not null default 'ignore'
 ddns_update_style  | text| not null default 'interim'
 description| text|

Best regards,
Roelof

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



Re: [SQL] double linked list

2003-02-01 Thread Jan Hidders
Juergen wrote:
>
>However, I dont store a consistent tree structure. The table at hand
>is more a kind of a collection of graphs where I want to find all
>possible paths between a given starting point and a given end point

A collection of graphs? As you presented the problem it was simply a single
graph.

That's not possible in a single SQL statement without using some form of
recursion such as the CONNECT BY in Oracle that was already mentioned or the
recursive queries as are possible in RDB. Another "poor man's solution" could for
example be to add a table Reachable(node, from_a, to_b) with 'from_a' and
'from_b' boolean field that indicate that the node is reachable from a and
that b is reachable from this node. You could compute this relation by
repeating a certain SQL update statement that:
1. sets from_a of node n to true if there is a node n' that is reachable
   from a and there is an edge from n' to n, and
2. set to_b of node n to tur if there is a node n' that leads to b and there
   is an edge from n to n'.
You repeat that until no more flags are changed. Then you select only those
edges for which the begin and node have both flags set to true.


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



Re: [SQL] double linked list

2003-02-01 Thread Juergen
heavy stuff Celko. I would lie if I would pretend I fully understand
Your answer. I'll let sink it in.

However, I dont store a consistent tree structure. The table at hand
is more a kind of a collection of graphs where I want to find all
possible paths between a given starting point and a given end point

cheers

Juergen
 
[EMAIL PROTECTED] (--CELKO--) wrote in message 
news:<[EMAIL PROTECTED]>...
> >> I've got a table called 'link_t' containing a collection of seller
> -
> buyer relations between two parties. <<
> 
> That is not a real linked list, but let's ignore bad terminology.  One
> way to do this is with cursors, but they will take time and trend to
> be proprietary.
> 
> Anohter way is to build a tree, with the first seller as the root and
> the final buyer as a leaf node.
> 
> The usual example of a tree structure in SQL books is called an
> adjacency list model and it looks like this:
> 
> CREATE TABLE OrgChart 
> (emp CHAR(10) NOT NULL PRIMARY KEY, 
>   boss CHAR(10) DEFAULT NULL REFERENCES OrgChart(emp), 
>   salary DECIMAL(6,2) NOT NULL DEFAULT 100.00);
> 
> OrgChart 
> emp   boss  salary 
> ===
> 'Albert' 'NULL'1000.00
> 'Bert''Albert'   900.00
> 'Chuck'   'Albert'   900.00
> 'Donna'   'Chuck'800.00
> 'Eddie'   'Chuck'700.00
> 'Fred''Chuck'600.00
> 
> Another way of representing trees is to show them as nested sets.
> Since SQL is a set oriented language, this is a better model than the
> usual adjacency list approach you see in most text books. Let us
> define a simple OrgChart table like this, ignoring the left (lft) and
> right (rgt) columns for now. This problem is always given with a
> column for the employee and one for his boss in the textbooks. This
> table without the lft and rgt columns is called the adjacency list
> model, after the graph theory technique of the same name; the pairs of
> emps are adjacent to each other.
> 
> CREATE TABLE OrgChart 
> (emp CHAR(10) NOT NULL PRIMARY KEY, 
>   lft INTEGER NOT NULL UNIQUE CHECK (lft > 0), 
>   rgt INTEGER NOT NULL UNIQUE CHECK (rgt > 1),
>   CONSTRAINT order_okay CHECK (lft < rgt) );
> 
> OrgChart 
> emp lft rgt 
> ==
> 'Albert'  1   12 
> 'Bert'23 
> 'Chuck'   4   11 
> 'Donna'   56 
> 'Eddie'   78 
> 'Fred'9   10 
> 
> The organizational chart would look like this as a directed graph:
> 
> Albert (1,12)
> /\
>   /\
> Bert (2,3)Chuck (4,11)
>/|   \
>  /  | \
>/|   \
>  /  | \
> Donna (5,6)  Eddie (7,8)  Fred (9,10)
> 
> The first table is denormalized in several ways. We are modeling both
> the OrgChart and the organizational chart in one table. But for the
> sake of saving space, pretend that the names are job titles and that
> we have another table which describes the OrgChart that hold those
> positions.
> 
> Another problem with the adjacency list model is that the boss and
> employee columns are the same kind of thing (i.e. names of OrgChart),
> and therefore should be shown in only one column in a normalized
> table.  To prove that this is not normalized, assume that "Chuck"
> changes his name to "Charles"; you have to change his name in both
> columns and several places. The defining characteristic of a
> normalized table is that you have one fact, one place, one time.
> 
> The final problem is that the adjacency list model does not model
> subordination. Authority flows downhill in a hierarchy, but If I fire
> Chuck, I disconnect all of his subordinates from Albert. There are
> situations (i.e. water pipes) where this is true, but that is not the
> expected situation in this case.
> 
> To show a tree as nested sets, replace the emps with ovals, then nest
> subordinate ovals inside each other. The root will be the largest oval
> and will contain every other emp. The leaf emps will be the innermost
> ovals with nothing else inside them and the nesting will show the
> hierarchical relationship. The rgt and lft columns (I cannot use the
> reserved words LEFT and RIGHT in SQL) are what shows the nesting.
> 
> If that mental model does not work, then imagine a little worm
> crawling anti-clockwise along the tree. Every time he gets to the left
> or right side of a emp, he numbers it. The worm stops when he gets all
> the way around the tree and back to the top.
> 
> This is a natural way to model a parts explosion, since a final
> assembly is made of physically nested assemblies that final break down
> into separate parts.
> 
> At this point, the boss column is both redundant and denormalized, so
> it can be dropped. Also, note that the tree structure can be kept in
> one table and all the information about a emp can be put in a second
> table and they can be joined on employee number for queries.
> 
> To convert the graph into a nested 

[SQL] Help with a query for charting

2003-02-01 Thread Andrew Veitch
I'm trying to do a query to count the number of tickets opened on each day
of a month. It'll always be from the 1st to the end of the month. This does
it:

SELECT TO_CHAR(DATE_TRUNC('day',date_opened),'DD') AS day, COUNT(*)
FROM ticket GROUP BY DATE_TRUNC('day', date_opened)
WHERE ;

But it doesn't give me a zero for the days when no tickets were opened -
which I really need because I want to graph the result.

I could do this in the application code but that doesn't seem right.

Help would be great.

Andrew


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster



[SQL] how can i convert a substring to a date?

2003-02-01 Thread joe.guyot
greetings all!

i have a  string data from a view that is a packed field. it
contains a date, a time and a user's initials. i'm trying to extract
the date portion in a pg 7 view. the data originally came from a ms
sql 7 table that has since been converted into a pg 7 table.

in the ms sql 7 view the date was extracted  as follows:

convert(timestamp, substring(creat, 1, 8), 120) = 'createdate'

where creat is the packed field from the original table and
'createdate' is the extracted date portion. the data would typically
look like: 20071623XYX. the result is '2001-11-17'.

i've reviewed documentation, on line books and several threads in
this and related newsgroups and can't seem to come up with a  decent
solution.

i've tried various combinations of this in a pg 7 view:

to_date(substr(creat,1,8),'-MM-DD') = 'createdate'
to_date(substring(creat from 1 for 8),'-MM-DD') =
'createdate'
to_timestamp(substr(creat,1,8),'-MM-DD') = 'createdate'
to_timestamp(substrsting(creat from 1 for 8),'-MM-DD') =
'createdate'

and continually get different errors:
"bad date external representation 'createdate'"
or
"bad timestamp external representation 'createdate'"

i'm sure this has an obvious solution but i can't seem to find it.
any suggestions are appreciated.


regards,
yusuf

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



Re: [SQL] Filter function

2003-02-01 Thread Evgen Potemkin
it's base-7.3.1 from one of the russian mirrors.

regards,

---
.evgen

On Wed, 29 Jan 2003, Tom Lane wrote:

> Evgen Potemkin <[EMAIL PROTECTED]> writes:
> > term2=>select * from tab where tab=1;
> > ERROR:  exprType: Do not know how to get type for 711 node
>
> What release is this?  I get
>   Relation reference "tab" cannot be used in an expression
> in 7.3 and CVS tip, and
>   Attribute 'tab' not found
> in prior releases.
>
>   regards, tom lane
>


---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [SQL] double linked list

2003-02-01 Thread Ryan
are you  joe celko, guy who wrote those sql books?

"--CELKO--" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> >> The table at hand is more a kind of a collection of graphs where I
> want to find all possible paths between a given starting point and a
> given end point. <<
>
> For the reachabiity index of a general graph, you need Warshal's
> algorithm.
>
> Let V = number of nodes in the graph
> Let A[i,j] be the adjacency matrix for the undirected graph
>
> FOR j:= 1 TO V
>  DO FOR i:= 1 TO V
>  DO IF A[i,j] = 1
> THEN FOR k := 1 TO V
>   DO IF A[j,k]] = 1
>  THEN A[i,k]] := 1;
>
> You can also do a summation to get the length of the path from i to j.
> You can concatenate names of the nodes into a string that gives the
> path, etc.
>
> Her is a first attempt at some SQL; I am sure it can be done better
>
> CREATE TABLE Graph
> (i CHAR(2) NOT NULL,
>  j CHAR(2) NOT NULL,
>  flag CHAR(1) NOT NULL DEFAULT 'n'
>CHECK (flag IN ('n', 'y')),
>  PRIMARY KEY (i,j));
>
> INSERT INTO Graph (i, j, flag)
>  SELECT DISTINCT G1.i, G2.j, 'y'
>FROM Graph AS G1, Graph AS G1
>   WHERE G1.i <> G2.j
> AND EXISTS
> (SELECT *
>FROM Graph AS G3
>   WHERE G3.i = G1.j
> AND G3.j = G2.i)
> AND NOT EXISTS
> (SELECT *
>FROM Graph AS G3
>   WHERE (G3.i = G1.i AND G3.j = G1.j))
>  OR (G3.i = G2.i AND G3.j = G2.j));
>
> You wll have to run this statement until the size of Graph does not
> change -- no new rows are being added.



---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



[SQL] Index File growing big.

2003-02-01 Thread PRAGATI SAVAIKAR

Hi !!

   We have "PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96"
installed on Linux (RedHat 7.2)
Our database size is 15 GB.
Since the database size was increasing and was about to cross the actual 
Hard Disk parttion Size, we moved the datafiles (also the index files) to 
another partition  and created link to them from the data directory.
This was working fine.
But what we found was , the index files(2 files) were not getting updated 
in the new partition, instead postgres had created another index file with name
"tableID".1  in the original data directory. The size of this file was 
356MB, 
The actual size of the data table is 1GB. and there were 2 indexes for the 
table. which were of size approximately=150MB.

But after we created link, those 2 index files were not getting updated, 
instead the new file with ".1" extension got created in the data directory 
(old parttion) and the same is getting updated everyday.

We dropped the table but the file with ".1" extension was not getting 
removed from data directory. We manually had to remove it.

Can U please suggest some way to avoid the file getting created when we 
move the data file (along with the index files) to another partition.


Thanks in Advance.



Regards,
Pragati.
   
   


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster



[SQL] how do i create a date from a substring???

2003-02-01 Thread joe.guyot
greetings all!

[i just became a member]

i have a  string data from a view that is a packed field. it
contains a date, a time and a user's initials. i'm trying to extract
the date portion in a pg 7 view. the data originally came from a ms
sql 7 table that has since been converted into a pg 7 table.

in the ms sql 7 view the date was extracted  as follows:

convert(timestamp, substring(creat, 1, 8), 120) = 'createdate'

where creat is the packed field from the original table and
'createdate' is the extracted date portion. the data would typically
look like: 20071623XYX. the result is '2001-11-17'.

i've reviewed documentation, on line books and several threads in
this and related newsgroups and can't seem to come up with a  decent
solution.

i've tried various combinations of this in a pg 7 view:

to_date(substr(creat,1,8),'-MM-DD') = 'createdate'
to_date(substring(creat from 1 for 8),'-MM-DD') =
'createdate'
to_timestamp(substr(creat,1,8),'-MM-DD') = 'createdate'
to_timestamp(substrsting(creat from 1 for 8),'-MM-DD') =
'createdate'

and continually get different errors:
"bad date external representation 'createdate'"
or
"bad timestamp external representation 'createdate'"

i'm sure this has an obvious solution but i can't seem to find it.
any suggestions are appreciated.


regards,
yusuf

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [SQL] [NOVICE] For each record in SELECT

2003-02-01 Thread Andrew McMillan
On Sat, 2003-02-01 at 10:21, Luis Magaña wrote:
> Hi,
> 
> I have a question here:
> 
> I have a table with this fields:
> 
> month
> description
> amount
> 
> now I have to write a query that retrieves the sum of the amount from
> the minimum month to the maximum month registered for each diferent
> description.
> 
> Of course there are cases when a particular description has not record
> for all the months in that period.  I mean, suppouse you have this
> records:
> 
> month description amount
> ---
> June  description1100 
> July  description1500
> Augustdescription1600
> June  description2300
> Augustdescription2400
> 
> how you write a query that outputs something like this:
> 
>   JuneJulyAugust
> --
> description1 |100 500 600
> description2 |300 0   400
> 
> My problem is for the 0 value.

If you have another table with columns like:

month   description

Junedescription1
Julydescription1
August  description1
Junedescription2
Julydescription2
August  description2

Then you will be able to do an outer join to it like:

SELECT * FROM t1 FULL OUTER JOIN t2 ON t1.month = t2.month AND
t1.description = t2.description

This will give you a NULL, rather than a zero, but your application
should be able to handle that detail.

You can also do this having two tables: one for the months, and another
for the descriptions:

SELECT * FROM months m CROSS JOIN descriptions d FULL OUTER JOIN values
v ON m.month = v.month AND d.description = v.description

I hope this is some use,
Andrew.
-- 
-
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201 MOB: +64(21)635-694OFFICE: +64(4)499-2267
   Survey for nothing with http://survey.net.nz/ 
-


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]



Re: [SQL] double linked list

2003-02-01 Thread --CELKO--
>> are you joe celko, guy who wrote those sql books? <<

Yes.

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly