Re: [GENERAL] limit table to one row

2009-06-10 Thread Jasen Betts
On 2009-06-09, Grzegorz Jaśkiewicz wrote: > 2009/6/9 Brandon Metcalf : > > >> I'm not sure I follow how this solves the problem. > > Well, surely if you just need one row, you need single value per key. > And that's the, imo , better solution to that problem, than limiting > number of rows. not r

Re: [GENERAL] limit table to one row

2009-06-09 Thread Octavio Alvarez
On Tue, 09 Jun 2009 08:24:01 -0700, Brandon Metcalf wrote: CREATE TABLE foo ( start DATE, length VARCHAR(10), ); I need to be able to get one value for each column at any given time. CREATE UNIQUE INDEX u ON foo ((start IS NOT NULL)); You would just make sure you SELECT FROM f

Re: [GENERAL] limit table to one row

2009-06-09 Thread Brandon Metcalf
g == gryz...@gmail.com writes: g> If you want to store period of time, why store it as varchar ? g> just store two rows g> create table foo( g> n varchar, g> val date g> ); g> and store two rows: g> "start", now(), g> "end", now()+'something '::interval g> Wouldn't that do, or is

Re: [GENERAL] limit table to one row

2009-06-09 Thread Grzegorz Jaśkiewicz
2009/6/9 Brandon Metcalf : > >  CREATE TABLE foo ( >    start  DATE, >    length VARCHAR(10), >  ); > > I need to be able to get one value for each column at any given time. > Specifically, I need to get a value for start and add the value for > length to get a time period.  Since your approach wo

Re: [GENERAL] limit table to one row

2009-06-09 Thread Brandon Metcalf
g == gryz...@gmail.com writes: g> 2009/6/9 Brandon Metcalf : g> > I'm not sure I follow how this solves the problem. g> Well, surely if you just need one row, you need single value per key. g> And that's the, imo , better solution to that problem, than limiting g> number of rows. Hm. Ma

Re: [GENERAL] limit table to one row

2009-06-09 Thread Grzegorz Jaśkiewicz
2009/6/9 Brandon Metcalf : > I'm not sure I follow how this solves the problem. Well, surely if you just need one row, you need single value per key. And that's the, imo , better solution to that problem, than limiting number of rows. -- GJ -- Sent via pgsql-general mailing list (pgsql-gene

Re: [GENERAL] limit table to one row

2009-06-09 Thread Brandon Metcalf
g == gryz...@gmail.com writes: g> just change whatever you are storing to be in vertical structure, g> instead of horizontal. so instead of create table foo(a int, b int, c g> int, etc), try: g> create table foo(name varchar, val int); g> common mistake I've seen committed by people.. I'm

Re: [GENERAL] limit table to one row

2009-06-09 Thread Jasen Betts
On 2009-06-04, Brandon Metcalf wrote: > Is there a way when creating a table to limit it to one row? That is, > without using a stored procedure? > > I searched the documentation, but didn't find anything. create a unique index, and a constraint to a single value on one of the columns :) -- S

Re: [GENERAL] limit table to one row

2009-06-08 Thread Merlin Moncure
On Sun, Jun 7, 2009 at 1:38 AM, Craig Ringer wrote: > Brandon Metcalf wrote: >> Is there a way when creating a table to limit it to one row?  That is, >> without using a stored procedure? >> >> I searched the documentation, but didn't find anything. >> > > > CREATE TABLE x (...); > > CREATE UNIQUE

Re: [GENERAL] limit table to one row

2009-06-06 Thread Craig Ringer
Brandon Metcalf wrote: > Is there a way when creating a table to limit it to one row? That is, > without using a stored procedure? > > I searched the documentation, but didn't find anything. > CREATE TABLE x (...); CREATE UNIQUE INDEX x_only_one_row ON ((1)); -- Craig Ringer -- Sent via pg

Re: [GENERAL] limit table to one row

2009-06-06 Thread Leif B. Kristensen
On Saturday 6. June 2009, Grzegorz Jaśkiewicz wrote: >just change whatever you are storing to be in vertical structure, >instead of horizontal. so instead of create table foo(a int, b int, c >int, etc), try: > >create table foo(name varchar, val int); > >common mistake I've seen committed by people

Re: [GENERAL] limit table to one row

2009-06-06 Thread Tom Lane
Merlin Moncure writes: > On Sat, Jun 6, 2009 at 2:07 PM, Tom Lane wrote: >> If you're willing to use a trigger, just insert the one allowed row >> and then install a trigger that throws error for any insert or delete >> attempt ... > what if you need to delete then insert? :-) Hmm ... I supposed

Re: [GENERAL] limit table to one row

2009-06-06 Thread Merlin Moncure
On Sat, Jun 6, 2009 at 2:07 PM, Tom Lane wrote: > Merlin Moncure writes: >> On Thu, Jun 4, 2009 at 4:13 PM, Brandon >> Metcalf wrote: >>> Is there a way when creating a table to limit it to one row?  That is, >>> without using a stored procedure? > >> you can also do it with a trigger. > > If you'

Re: [GENERAL] limit table to one row

2009-06-06 Thread Tom Lane
Merlin Moncure writes: > On Thu, Jun 4, 2009 at 4:13 PM, Brandon > Metcalf wrote: >> Is there a way when creating a table to limit it to one row?  That is, >> without using a stored procedure? > you can also do it with a trigger. If you're willing to use a trigger, just insert the one allowed ro

Re: [GENERAL] limit table to one row

2009-06-06 Thread Merlin Moncure
On Thu, Jun 4, 2009 at 4:13 PM, Brandon Metcalf wrote: > Is there a way when creating a table to limit it to one row?  That is, > without using a stored procedure? > > I searched the documentation, but didn't find anything. > > -- you can also do it with a trigger. create or replace function one_

Re: [GENERAL] limit table to one row

2009-06-06 Thread Grzegorz Jaśkiewicz
just change whatever you are storing to be in vertical structure, instead of horizontal. so instead of create table foo(a int, b int, c int, etc), try: create table foo(name varchar, val int); common mistake I've seen committed by people.. -- Sent via pgsql-general mailing list (pgsql-general@p

Re: [GENERAL] limit table to one row

2009-06-05 Thread Brandon Metcalf
p == pgmaili...@codecraft.se writes: p> On 4 jun 2009, at 22.17, Richard Broersma wrote: p> > On Thu, Jun 4, 2009 at 1:13 PM, Brandon Metcalf p> > wrote: p> >> Is there a way when creating a table to limit it to one row? That p> >> is, p> >> without using a stored procedure? p> > p> >

Re: [GENERAL] limit table to one row

2009-06-04 Thread Niklas Johansson
On 4 jun 2009, at 22.17, Richard Broersma wrote: On Thu, Jun 4, 2009 at 1:13 PM, Brandon Metcalf wrote: Is there a way when creating a table to limit it to one row? That is, without using a stored procedure? Sure just add a check constraint along the lines of: CONSTRAINT Only_one_row

Re: [GENERAL] limit table to one row

2009-06-04 Thread Brandon Metcalf
r == richard.broer...@gmail.com writes: r> On Thu, Jun 4, 2009 at 1:23 PM, Brandon Metcalf r> wrote: r> > Got it. ?Currently, it doesn't have a column for an ID, but I can add r> > one if this is the only way. r> Actually any column with a unique index on it will work. It doesn't r> hav

Re: [GENERAL] limit table to one row

2009-06-04 Thread Richard Broersma
On Thu, Jun 4, 2009 at 1:23 PM, Brandon Metcalf wrote: > Got it.  Currently, it doesn't have a column for an ID, but I can add > one if this is the only way. Actually any column with a unique index on it will work. It doesn't have to be primary key or even a serial id. ANSI-SQL 92 allows for

Re: [GENERAL] limit table to one row

2009-06-04 Thread Brandon Metcalf
r == richard.broer...@gmail.com writes: r> On Thu, Jun 4, 2009 at 1:13 PM, Brandon Metcalf r> wrote: r> > Is there a way when creating a table to limit it to one row? ?That is, r> > without using a stored procedure? r> Sure just add a check constraint along the lines of: r> CONSTRAINT On

Re: [GENERAL] limit table to one row

2009-06-04 Thread Richard Broersma
On Thu, Jun 4, 2009 at 1:13 PM, Brandon Metcalf wrote: > Is there a way when creating a table to limit it to one row?  That is, > without using a stored procedure? Sure just add a check constraint along the lines of: CONSTRAINT Only_one_row CHECK( tableuniqueid = 1 ); --assuming you row has

Re: [GENERAL] limit table to one row

2009-06-04 Thread Richard Broersma
On Thu, Jun 4, 2009 at 1:13 PM, Brandon Metcalf wrote: > Is there a way when creating a table to limit it to one row?  That is, > without using a stored procedure? Sure just add a check constraint along the lines of: CONSTRAINT Only_one_row CHECK( tableuniqueid = 1 ); --assuming you row has

[GENERAL] limit table to one row

2009-06-04 Thread Brandon Metcalf
Is there a way when creating a table to limit it to one row? That is, without using a stored procedure? I searched the documentation, but didn't find anything. -- Brandon -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.pos