472,334 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

How to find LIMIT in SQL standard

I have to file a bug about the implementation of some delivery report
database calls in the Kannel (open source WAP/SMS) server code.

Essentially the call (as defined below) asks for an update and adds a
LIMIT parameter on the end of the UPDATE. (eg update where x=1 limit 1).
Postgres doesn't like this and I assume it isn't SQL standards
compliant and need to refer to this in my bug report.

I've downloaded the sql document archives from
postgresql.org/postgresql/doc/sql but it isn't clear to me how to
discern what is legal in an UPDATE statement.

Help much appreciated!
Rory

static const char* sdb_get_limit_str()
{
switch (sdb_conn_type) {
case SDB_ORACLE:
return "AND ROWNUM < 2";
case SDB_OTHER:
default:
return "LIMIT 1";
}

...

sql = octstr_format("UPDATE %s SET %s=%d WHERE %s='%s' AND %s='%s' %s",
octstr_get_cstr(fields->table),
octstr_get_cstr(fields->field_status), status,
octstr_get_cstr(fields->field_smsc), octstr_get_cstr(smsc),
octstr_get_cstr(fields->field_ts), octstr_get_cstr(ts), sdb_get_limit_str());
--
Rory Campbell-Lange
<ro**@campbell-lange.net>
<www.campbell-lange.net>

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #1
6 7231
On Mon, 22 Sep 2003, Rory Campbell-Lange wrote:
I have to file a bug about the implementation of some delivery report
database calls in the Kannel (open source WAP/SMS) server code.

Essentially the call (as defined below) asks for an update and adds a
LIMIT parameter on the end of the UPDATE. (eg update where x=1 limit 1).
Postgres doesn't like this and I assume it isn't SQL standards
compliant and need to refer to this in my bug report.


Well, for SQL92, it looks like the correct section to start in is
13.10 (update statement: searched) which looks like:

UPDATE <table name>
SET <set clause list>
WHERE <search condition>

The last of those is the interesting one which is 8.12 (search condition)
<search condition> ::=
<boolean term>
| <search condition> OR <boolean term>

<boolean term> ::=
<boolean factor>
| <boolean term> AND <boolean factor>

<boolean factor> ::=
[ NOT ] <boolean test>

<boolean test> ::=
<boolean primary> [ IS [ NOT ] <truth value> ]

<truth value> ::=
TRUE
| FALSE
| UNKNOWN

<boolean primary> ::=
<predicate>
| <left paren> <search condition> <right paren>
Then 8.1 (predicate)

<predicate> ::=
<comparison predicate>
| <between predicate>
| <in predicate>
| <like predicate>
| <null predicate>
| <quantified comparison predicate>
| <exists predicate>
| <unique predicate>
| <match predicate>
| <overlaps predicate>

Also, since tables are effectively unordered, unless the other
where conditions are guaranteed to get a single row anyway which
row is modified is fairly indeterminate; this is only interesting
because it means that you don't necessarily get the same row
as a previous select (if any) would get. That's not always important,
but since update also has no way to order the rows that I know of,
if it were important you couldn't really get around it.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #2
Rory Campbell-Lange wrote:
Essentially the call (as defined below) asks for an update and adds a
LIMIT parameter on the end of the UPDATE. (eg update where x=1 limit 1).
Postgres doesn't like this and I assume it isn't SQL standards
compliant and need to refer to this in my bug report.


As far as I know you can not specify a limit for update in Postgres,
at least not in that way.

if you want to do

UPDATE foo SET a='bar' where b LIMIT 1;

this is possible in Postgres doing:

UPDATE foo SET a = 'bar
WHERE foo.oid IN
( SELECT f.oid
FROM foo f
WHERE b
LIMIT 1
);
This fail if the table are created without OID.
Regards
Gaetano Mendola

Nov 11 '05 #3
Rory Campbell-Lange writes:
I've downloaded the sql document archives from
postgresql.org/postgresql/doc/sql but it isn't clear to me how to
discern what is legal in an UPDATE statement.


Certainly LIMIT is not. Although LIMIT is a key word in the SQL standard,
it isn't used for anything, so you cannot use it in portable applications.

--
Peter Eisentraut pe*****@gmx.net
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #4
In an attempt to throw the authorities off his trail, ro**@campbell-lange.net (Rory Campbell-Lange) transmitted:
Essentially the call (as defined below) asks for an update and adds
a LIMIT parameter on the end of the UPDATE. (eg update where x=1
limit 1). Postgres doesn't like this and I assume it isn't SQL
standards compliant and need to refer to this in my bug report.


No, it appears to be your understanding of the SQL standards may be a
little bit deficient.

LIMIT is a reserved word in SQL, but its use has not been
standardized. If you use LIMIT, then your query isn't compliant with
the standards, and the bug isn't in PostgreSQL, but rather is in your
code.

And what you are trying to do doesn't seem to make terribly much
sense. It sounds as though you're happy updating any random record so
long as it resembles the ones you think you might be updating.
Perhaps you should use, as search criteria, elements in a unique key,
so that you can be assured that the row will be unique.
--
If this was helpful, <http://svcs.affero.net/rm.php?r=cbbrowne> rate me
http://www.ntlug.org/~cbbrowne/x.html
Rules of the Evil Overlord #90. "I will not design my Main Control
Room so that every workstation is facing away from the door."
<http://www.eviloverlord.com/>
Nov 11 '05 #5
Thanks for the reply, Stephan. Sorry about the late reply.

Your dissection of the standard (and thanks for the translation, by
the way!) is a clear reason to use unique row ids. Unfortunately the
project I am reporting bugs on does not do this at present.

Many kind regards,
Rory

On 22/09/03, Stephan Szabo (ss****@megazone.bigpanda.com) wrote:
On Mon, 22 Sep 2003, Rory Campbell-Lange wrote:
I have to file a bug about the implementation of some delivery report
database calls in the Kannel (open source WAP/SMS) server code.

Essentially the call (as defined below) asks for an update and adds a
LIMIT parameter on the end of the UPDATE. (eg update where x=1 limit 1).
Postgres doesn't like this and I assume it isn't SQL standards
compliant and need to refer to this in my bug report.


Well, for SQL92, it looks like the correct section to start in is
13.10 (update statement: searched) which looks like:

UPDATE <table name>
SET <set clause list>
WHERE <search condition>

The last of those is the interesting one which is 8.12 (search condition)
<search condition> ::=
<boolean term>
| <search condition> OR <boolean term>

<boolean term> ::=
<boolean factor>
| <boolean term> AND <boolean factor>

<boolean factor> ::=
[ NOT ] <boolean test>

<boolean test> ::=
<boolean primary> [ IS [ NOT ] <truth value> ]

<truth value> ::=
TRUE
| FALSE
| UNKNOWN

<boolean primary> ::=
<predicate>
| <left paren> <search condition> <right paren>
Then 8.1 (predicate)

<predicate> ::=
<comparison predicate>
| <between predicate>
| <in predicate>
| <like predicate>
| <null predicate>
| <quantified comparison predicate>
| <exists predicate>
| <unique predicate>
| <match predicate>
| <overlaps predicate>

Also, since tables are effectively unordered, unless the other
where conditions are guaranteed to get a single row anyway which
row is modified is fairly indeterminate; this is only interesting
because it means that you don't necessarily get the same row
as a previous select (if any) would get. That's not always important,
but since update also has no way to order the rows that I know of,
if it were important you couldn't really get around it.

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

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #6
On Thu, 25 Sep 2003, Rory Campbell-Lange wrote:
Thanks for the reply, Stephan. Sorry about the late reply.

Your dissection of the standard (and thanks for the translation, by
the way!) is a clear reason to use unique row ids. Unfortunately the
project I am reporting bugs on does not do this at present.


Well, if you're looking for a PostgreSQL only solution (to throw in the
switch), I think someone already sent a query using oid and a subselect.
It's not going to perform super well probably and will only work on
tables with oids, but it should only update one row.

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

http://archives.postgresql.org

Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
SQL Server 2000 SP3 on a Dell dual 2.4GHz Xeon box 3GB RAM Windows 2K SP4. Two aplication dbs, each less than 2GB in size. Had a problem where...
2
by: Mike | last post by:
New to PHP and MySQL. Using PHP5 and MySQL 4.1 Windows XP Pro IIS 5.1 I'm trying to page a recordset, and am using a LIMIT clause to fetch a...
11
by: JoshuaF | last post by:
hello everyone i am very new to postgresql 7.3.3 and am using it on my mac G4 OS X and i am having some trouble which i hope you can help me out...
3
by: Roderick A. Anderson | last post by:
I'm dealing with a project that requires me to query a MS SQL Server. Not a PostgreSQL issue I know but I want to ask if the LIMIT modifier is SQL...
0
by: D. Dante Lorenso | last post by:
I need to know that original number of rows that WOULD have been returned by a SELECT statement if the LIMIT / OFFSET where not present in the...
2
by: 144.16.64.4 [shishir] | last post by:
what is the upper limit on the number of parameters to a function in C ? what is the mechanism by which parameters are passed in C, for instance...
8
by: Peter Ballard | last post by:
Hi all, I've got a C program which outputs all its data using a statement of the form: putchar(ch, outfile); This has worked fine for years...
10
by: salty | last post by:
.... when no one here has an answer? Does MS offer support for its programming products where that support doesn't cost an arm and a leg, but...
4
by: Alec MacLean | last post by:
Is anyone aware of a size limit imposed on the subject text when using the System.Net.Mail library? I'm getting problems of message not being...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.