Subject | non-ansi LIMIT on DELETE |
---|---|
Author | jrmrenegade |
Post date | 2007-01-20T17:31:18Z |
The syntax for a single-table DELETE statement in MySQL looks like this:
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
In an attempt to generate functionally identical statements in other
databases, I've run up against a roadblock with Firebird. PostgreSQL
also does not directly support limiting the number of rows to delete
that meet conditions because it's both non-ANSI and bad style.
However, apparently PostgreSQL has a unique identifier called a ctid
for each row that can be utilized in with a subquery like so:
DELETE FROM a WHERE ctid=(SELECT ctid FROM a WHERE b=3 LIMIT 1);
which is the function equivalent of MySQL's:
DELETE FROM a WHERE b=3 LIMIT 1;
So my question is: Is there any technique that I can apply to
"emulate" the LIMIT option for DELETE statements in Firebird?
I'm not applying this for a specific case, but rather using it as a
generic database interface. Thanks for your time, I've looked at this
for a couple of hours and I'm just stumped.
John
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
In an attempt to generate functionally identical statements in other
databases, I've run up against a roadblock with Firebird. PostgreSQL
also does not directly support limiting the number of rows to delete
that meet conditions because it's both non-ANSI and bad style.
However, apparently PostgreSQL has a unique identifier called a ctid
for each row that can be utilized in with a subquery like so:
DELETE FROM a WHERE ctid=(SELECT ctid FROM a WHERE b=3 LIMIT 1);
which is the function equivalent of MySQL's:
DELETE FROM a WHERE b=3 LIMIT 1;
So my question is: Is there any technique that I can apply to
"emulate" the LIMIT option for DELETE statements in Firebird?
I'm not applying this for a specific case, but rather using it as a
generic database interface. Thanks for your time, I've looked at this
for a couple of hours and I'm just stumped.
John