Re: offset for query result ??

Lists: pgsql-general
From: Jeff Boes <jboes(at)nexcerpt(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: pg_constraint missing many entries?
Date: 2003-11-17 20:20:54
Message-ID: 0687bc5bd66d644bc992c688abf337b0@news.teranews.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Almost all of my foreign key definitions are NOT present in
pg_constraint. However, they do exist as triggers. It appears that *new*
foreign keys, whether defined in new tables or added on via "ALTER
TABLE" commands, make it into pg_constraint, but the "old" stuff that
was present from before our 7.3 upgrade, exists only as triggers.

1) Is this a bug?

2) Is there any way to "refresh" pg_constraint? (I'm experimenting with
a tool that graphs a schema, and it needs a bit of code written to
determine from a table and column name whether that column is a foreign
key, and to what table. pg_constraint where contype = 'f' seems to be
the ticket, but on my database it's inadequate.)

--
Jeff Boes vox 269.226.9550 ext 24
Database Engineer fax 269.349.9076
Nexcerpt, Inc. http://www.nexcerpt.com
...Nexcerpt... Extend your Expertise


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Jeff Boes <jboes(at)nexcerpt(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pg_constraint missing many entries?
Date: 2003-11-17 20:55:17
Message-ID: 20031117205516.GA862@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

That's right, pg_constraint didn't exist before 7.3. In the contrib
directory there is a script called adddepend which attempts to create the
missing records for you.

On Mon, Nov 17, 2003 at 08:20:54PM +0000, Jeff Boes wrote:
> Almost all of my foreign key definitions are NOT present in
> pg_constraint. However, they do exist as triggers. It appears that *new*
> foreign keys, whether defined in new tables or added on via "ALTER
> TABLE" commands, make it into pg_constraint, but the "old" stuff that
> was present from before our 7.3 upgrade, exists only as triggers.
>
> 1) Is this a bug?
>
> 2) Is there any way to "refresh" pg_constraint? (I'm experimenting with
> a tool that graphs a schema, and it needs a bit of code written to
> determine from a table and column name whether that column is a foreign
> key, and to what table. pg_constraint where contype = 'f' seems to be
> the ticket, but on my database it's inadequate.)
>
>
> --
> Jeff Boes vox 269.226.9550 ext 24
> Database Engineer fax 269.349.9076
> Nexcerpt, Inc. http://www.nexcerpt.com
> ...Nexcerpt... Extend your Expertise
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> "All that is needed for the forces of evil to triumph is for enough good
> men to do nothing." - Edmond Burke
> "The penalty good people pay for not being interested in politics is to be
> governed by people worse than themselves." - Plato


From: Kathy Zhu <Kathy(dot)Zhu(at)Sun(dot)COM>
To: pgsql-general(at)postgresql(dot)org
Subject: offset for query result ??
Date: 2003-11-17 23:17:20
Message-ID: 3FB95700.403A4FA9@Sun.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi all,

I know we have LIMIT to limit the number of rows returned, I wonder if there is
a way to indicate an offset.

e.g.

Select * from Test offset 10, limit 4;

retrieve all Test, return 4 rows from the 10th row

thanks,
kathy


From: Troels Arvin <troels(at)arvin(dot)dk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: offset for query result ??
Date: 2003-11-17 23:25:36
Message-ID: pan.2003.11.17.23.25.36.351685@arvin.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Mon, 17 Nov 2003 16:17:20 -0700, Kathy Zhu wrote:

> I know we have LIMIT to limit the number of rows returned, I wonder if
> there is a way to indicate an offset.
>
> e.g.
>
> Select * from Test offset 10, limit 4;

Make that

SELECT *
FROM Test
LIMIT 4 OFFSET 10;

> retrieve all Test, return 4 rows from the 10th row

Almost. In PostgreSQL, OFFSET x means skip the first x rows. See also
http://www.postgresql.org/docs/7.4/static/sql-select.html#SQL-LIMIT

--
Greetings from Troels Arvin, Copenhagen, Denmark


From: Alex Satrapa <alex(at)lintelsys(dot)com(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: offset for query result ??
Date: 2003-11-17 23:59:22
Message-ID: 3FB960DA.6090604@lintelsys.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Kathy Zhu wrote:
> I know we have LIMIT to limit the number of rows returned, I wonder if there is
> a way to indicate an offset.

> Select * from Test offset 10, limit 4;

As per the PostgreSQL documentation, specifically the page on the
"SELECT" SQL command:

LIMIT Clause

LIMIT { count | ALL }
OFFSET start

where count specifies the maximum number of rows to return, and start
specifies the number of rows to skip before starting to return rows.

so the query you want is:

SELECT * FROM Test LIMIT 4 OFFSET 10;

Alex


From: Jeff Boes <jboes(at)nexcerpt(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Bug in adddepend (was: pg_constraint missing many entries?)
Date: 2003-11-18 14:07:19
Message-ID: 31e9e0ad0c3bfc4a6c85bb0e9af94070@news.teranews.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Martijn van Oosterhout wrote:
> That's right, pg_constraint didn't exist before 7.3. In the contrib
> directory there is a script called adddepend which attempts to create the
> missing records for you.
>

And much to my dismay, it has a bug (or a serious limitation).

Table (before):

...

Indexes: ix_foo_1 unique(fn_myfunc(foo_column))

becomes

Table (after):

...

Indexes: ix_foo_1 unique(foo_column))

That is, the script turned a functional index into an index on a column.
Bad, bad news. It's fortunate I did this on our test system; it's
unfortunate that I did it at the end of the day. Overnight, we ran a few
HUNDRED THOUSAND queries against a large table using no index ...

--
Jeff Boes vox 269.226.9550 ext 24
Database Engineer fax 269.349.9076
Nexcerpt, Inc. http://www.nexcerpt.com
...Nexcerpt... Extend your Expertise