Re: [SQL] Move table between schemas

2004-11-16 Thread Andrew Sullivan
On Tue, Nov 16, 2004 at 10:02:34AM +0100, Markus Schaber wrote: Hello, Is there an easy way to move a table to another schema in PostgreSQL 7.4? ALTER TABLE and ALTER SCHEMA don't have this options. CREATE TABLE newschema.newtable AS SELECT * FROM oldschema.oldtable oughta work. A --

[SQL] tree structure photo gallery date quiery

2004-11-16 Thread Gary Stainburn
Hi folks. I'm looking at the possibility of implementing a photo gallery for my web site with a tree structure, something like: create table gallery ( id serial, parent int4, name varchar(40), primary key (id)); create table photos ( pid serial, id int4 references gallery not null, added

Re: [SQL] Move table between schemas

2004-11-16 Thread Achilleus Mantzios
O Andrew Sullivan Nov 16, 2004 : On Tue, Nov 16, 2004 at 10:02:34AM +0100, Markus Schaber wrote: Hello, Is there an easy way to move a table to another schema in PostgreSQL 7.4? ALTER TABLE and ALTER SCHEMA don't have this options. CREATE TABLE newschema.newtable AS SELECT *

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread sad
On Tuesday 16 November 2004 14:29, Gary Stainburn wrote: Hi folks. I'm looking at the possibility of implementing a photo gallery for my web site with a tree structure How would I go about creating a view to show a) the number of photos in a gallery and b) the timestamp of the most recent

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread Rod Taylor
On Tue, 2004-11-16 at 11:29 +, Gary Stainburn wrote: How would I go about creating a view to show a) the number of photos in a gallery and b) the timestamp of the most recent addition for a gallery, so that it interrogates all sub-galleries? There isn't a very simple answer to that

[SQL] Table definition

2004-11-16 Thread Bruno Prévost
Title: Les consultants Interaction | stationery Hi, Anybody know how to obtain the table definition in text. Something like "select definition from pg_catalog.pg_views where viewname = 'xxx'" but fora table. Thanks Bruno

Re: [SQL] Table definition

2004-11-16 Thread Peter Eisentraut
Am Dienstag, 16. November 2004 15:04 schrieb Bruno Prévost: Anybody know how to obtain the table definition in text. Use pg_dump. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---(end of broadcast)--- TIP 6: Have you searched our

Re: [SQL] Table definition

2004-11-16 Thread Goutam Paruchuri
Title: Les consultants Interaction | stationery Probably there is no direct way get the definition (i could not find one atleast). You can probably write a custom function which gives all columns, indexes and formulate a create table statement (text definition). Letus know if you find a way

Re: [SQL] Table definition

2004-11-16 Thread Sam Mason
Bruno Prévost wrote: Anybody know how to obtain the table definition in text. Not quite sure if this is quite what you're after, but would: $ pg_dump -st foo help at all? It gives out the SQL that you would need to enter to re-create the table. Sam ---(end of

Re: [SQL] Table definition

2004-11-16 Thread Bruno Prévost
I need to use it in sql. Thk Bruno - Original Message - From: Peter Eisentraut [EMAIL PROTECTED] To: Bruno Prévost [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, November 16, 2004 10:16 AM Subject: Re: [SQL] Table definition Am Dienstag, 16. November 2004 15:04 schrieb Bruno

Re: [SQL] Table definition

2004-11-16 Thread Peter Eisentraut
Am Dienstag, 16. November 2004 16:40 schrieb Bruno Prévost: I need to use it in sql. There is no direct way to do this in SQL, but I can offer you the following alternative: CREATE FUNCTION get_table_definition(text) RETURNS text AS ' #!/bin/sh pg_dump -t $1 ' LANGUAGE plsh; :) -- Peter

Re: [SQL] Table definition

2004-11-16 Thread Bruno Prévost
It could help me, but pg_dump give all foreigns key and index creation. I'm not sure if it's not better to write a custom function in plpgsql. Bruno - Original Message - From: Peter Eisentraut [EMAIL PROTECTED] To: Bruno Prévost [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday,

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread Pierre-Frédéric Caillaud
I'm looking at the possibility of implementing a photo gallery for my web site with a tree structure, something like: You don't really want a tree structure, because one day you'll want to put the same photo in two galleries. Suppose you take a very interesting photo of celery during your

Re: [SQL] select using regexp does not use indexscan

2004-11-16 Thread carex
[EMAIL PROTECTED] (Tom Lane) wrote in message news:[EMAIL PROTECTED]... Stephan Szabo [EMAIL PROTECTED] writes: On Tue, 9 Nov 2004, carex wrote: And it works also perfectly with Gentoo. So,is this a typical Redhat Enterprise problem ? Or do I overlook something ?? IIRC, in 7.3.x,

[SQL] View and subselect related questions

2004-11-16 Thread Jakub Kaniewski
I have two data tables AUTHORS and BOOKS, and one indirection table AUTHOR_BOOKS which allow me to make n:m links. Now I want to create view that allow user to select all books of specyfic author - user should use query like this SELECT * FROM booksvw WHERE idauthor=xxx. I know two queries

[SQL] Counting Distinct Records

2004-11-16 Thread Thomas F . O'Connell
I am wondering whether the following two forms of SELECT statements are logically equivalent: SELECT COUNT( DISTINCT table.column ) ... and SELECT DISTINCT COUNT( * ) ... If they are the same, then why is the latter query much slower in postgres when applied to the same FROM and WHERE clauses?

Re: [SQL] Counting Distinct Records

2004-11-16 Thread Stephan Szabo
On Tue, 16 Nov 2004, Thomas F.O'Connell wrote: I am wondering whether the following two forms of SELECT statements are logically equivalent: SELECT COUNT( DISTINCT table.column ) ... and SELECT DISTINCT COUNT( * ) ... Not in general. The former counts how many distinct table.column

Re: [SQL] Counting Distinct Records

2004-11-16 Thread Thomas F.O'Connell
Is there another way to accomplish what the former is doing, then? For practical reasons, I'd like to come up with something better. For theoretical curiosity, I'd like to know whether there's a way to combine COUNT and DISTINCT that still allows one to reference * rather than naming specific

[SQL] finding gaps in dates

2004-11-16 Thread Matt Nuzum
I have a logging application that should produce an entry in the database every minute or so, give or take a few seconds. I'm interested in finding out a: what minutes don't have a record and b: periods where the gap exceeded a certain amount of time. The only way I can think of to do it is to

Re: [SQL] finding gaps in dates

2004-11-16 Thread Pierre-Frédéric Caillaud
I have a logging application that should produce an entry in the database every minute or so, give or take a few seconds. I'm interested in finding out a: what minutes don't have a record and b: periods where the gap exceeded a certain amount of time. Is this not the same question ?

Re: [SQL] Move table between schemas

2004-11-16 Thread Andrew Sullivan
On Tue, Nov 16, 2004 at 02:30:09PM +0200, Achilleus Mantzios wrote: CREATE TABLE newschema.newtable AS SELECT * FROM oldschema.oldtable oughta work. What about indexes, constraints, sequences,etc...??? You'll have to create those too, I'm afraid. I don't know of a way to move

Re: [SQL] Counting Distinct Records

2004-11-16 Thread Stephan Szabo
On Tue, 16 Nov 2004, Thomas F.O'Connell wrote: Is there another way to accomplish what the former is doing, then? The only thing I can think of is a subselect in from that uses distinct. select count(*) from (select distinct ...) foo That also theoretically allows you to use select distinct *

Re: [SQL] Counting Distinct Records

2004-11-16 Thread Thomas F.O'Connell
Hmm. I was more interested in using COUNT( * ) than DISTINCT *. I want a count of all rows, but I want to be able to specify which columns are distinct. That's definitely an interesting approach, but testing doesn't show it to be appreciably faster. If I do a DISTINCT *, postgres will attempt

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread Gary Stainburn
On Tuesday 16 November 2004 1:08 pm, sad wrote: On Tuesday 16 November 2004 14:29, Gary Stainburn wrote: Hi folks. I'm looking at the possibility of implementing a photo gallery for my web site with a tree structure How would I go about creating a view to show a) the number of

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread Mike Rylander
Gary, If you're not to worried about tying yourself to Postgres and you're sure you want to create a tree structure, you may want to check out the ltree contrib module. It will allow you to create an index over the entire tree, and will allow you to use real names instead of INTs for the nodes