Re: [SQL] Extract date from week

2005-12-14 Thread Neil Dugan
Jaime Casanova wrote: On 11/8/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Hi Looking the e-mail I remembered a question. I saw that "select extract (week from now()::date)" will return the week number of current year. But, how can I convert a week to the first reference date. Ex: select ex

Re: [SQL] Multi-row update w. plpgsql function

2005-12-14 Thread Daniel Hertz
Aaron Koning wrote: Owen makes a good point. Check that you are using the [] in the HTML input variable for the checkboxes. Like: 1 2 3 4 Aaron On 12/13/05, Owen Jacobson <[EMAIL PROTECTED]> wr I'm not familiar with Cocoon, but I'd expect that to return only the first of the "approved

Re: [SQL] # of 5 minute intervals in period of time ...

2005-12-14 Thread Bruno Wolff III
On Tue, Dec 13, 2005 at 18:34:36 -0400, "Marc G. Fournier" <[EMAIL PROTECTED]> wrote: > > Is there a simpler way of doing this then: > > select (date_part('epoch', now()) - > date_part('epoch', now() - '30 days'::interval)) / ( 5 * 60 ); Are you trying to do this: select extract(epoch

Re: [SQL] Defaulting a column to 'now'

2005-12-14 Thread Keith Worthington
On Wed, 14 Dec 2005 13:10:50 -0500, Ken Winter wrote > How can a column's default be set to 'now', meaning 'now' as of when each > row is inserted? > > For example, here's a snip of DDL: > > create table personal_data (. > > effective_date_and_time TIMESTAMP WITH TIME ZONE not null default > 'n

Re: [SQL] Defaulting a column to 'now'

2005-12-14 Thread Bricklen Anderson
Ken Winter wrote: How can a column’s default be set to ‘now’, meaning ‘now’ as of when each row is inserted? For example, here’s a snip of DDL: create table personal_data (… effective_date_and_time TIMESTAMP WITH TIME ZONE not null default 'now',… try with now(), instead of now ...

Re: [SQL] Defaulting a column to 'now'

2005-12-14 Thread Tom Lane
"Ken Winter" <[EMAIL PROTECTED]> writes: > How can a column's default be set to 'now', meaning 'now' as of when each > row is inserted? You need a function, not a literal constant. The SQL-spec way is CURRENT_TIMESTAMP (which is a function, despite the spec's weird idea that it should be

[SQL] Defaulting a column to 'now'

2005-12-14 Thread Ken Winter
How can a column’s default be set to ‘now’, meaning ‘now’ as of when each row is inserted?   For example, here’s a snip of DDL:   create table personal_data (… effective_date_and_time TIMESTAMP WITH TIME ZONE not null default 'now',…   The problem is, when PostgreSQL processes this D

Re: [SQL] Finding out to which table a specific row belongs

2005-12-14 Thread Michael Fuhr
On Wed, Dec 14, 2005 at 06:26:23PM +0100, Jost Degenhardt wrote: > I have the following problem: My database consists of several tables > that are inherited from each other with one single supertable on top of > that hierarchy. Now I would like to select a single row in that > supertable and wan

[SQL] Finding out to which table a specific row belongs

2005-12-14 Thread Jost Degenhardt
Hi there, I have the following problem: My database consists of several tables that are inherited from each other with one single supertable on top of that hierarchy. Now I would like to select a single row in that supertable and want to find out to which of the tables in the hierarchy it belo

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
so, after the needed modifications the SQL schema is the following -- SQL schema for business-test-db2 CREATE TABLE customers ( customer_code serial UNIQUE, alfa_customer_code varchar(6), customer_name character varying(250) NOT NULL, address character varying(250) NOT NULL, city chara

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
[cut] Given this table layout, I'm gonna take a wild guess and ask if you're coming from MySQL and expecting the second serial order_code to be a sub-autoincrement to id? no, always used PostgreSQL, but i'm having a deeper approach now, until now i've been using th ORDBMS in a very 'easy' mann

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
[cut] It means what it says. You have defined table orders with a primary key of (id,order_code). This means that the combination of (id,order_code) must be unique. yes, that was my thought, and in that context, i thought it could be correct in order to have uniqueness for creating forei

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
Jaime Casanova wrote: [...unnecesary...] CREATE TABLE orders ( id serial, order_code serial, customer_code integer REFERENCES customers (customer_code) NOT NULL, order_date time without time zone NOT NULL, remote_ip inet NOT NULL, order_time timestamp with time zone NOT NULL, order_t

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
John McCawley wrote: Table orders defines the column order_code as a serial, which simple makes a trigger which gives a new value to the column on insert. Note that there is NO guarantee that ths column will be unique. You can manually update the value to whatever you want. If you wish this

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
[cut] order_code is not by itself unique --- SERIAL doesn't guarantee that. that was my misunderstanding, i thought (misunderstood) that 'serial' implied 'unique' I'm not sure why you are declaring the primary key of orders as being the combination of *two* serial columns, i thought it

Re: [SQL] Multi-row update w. plpgsql function

2005-12-14 Thread Magnus Hagander
> > Imagine a table called 'message_table': > > > > mid | message | status > > +-+--- > > 1 | Text1 | H > > 2 | Text2 | H > > 3 | Text3 | H > > 4 | Text4 | H > > > > A web page presents the user with all messages flagged with > 'H'. User > > checks m

Re: [SQL] Multi-row update w. plpgsql function

2005-12-14 Thread Aarni Ruuhimäki
Hi, If your checkboxes are like input type="checkbox" name="approved" value="1" input type="checkbox" name="approved" value="2" input type="checkbox" name="approved" value="3" input type="checkbox" name="approved" value="4" and 1, 3 and 4 are checked your form data will be approved=1,3,4 Then y