473,800 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Single Row Table?

Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?

Thanks and regards,

Yateen V. Joshi


Nov 23 '05 #1
13 2720
On Fri, Aug 27, 2004 at 13:32:07 +0530,
Yateen Joshi <yj****@starent networks.com> wrote:
Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?


A simple way to force this is to add a primary key and a constraint
that forces the primary key to be a particular value.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #2
On Sun, 2004-08-29 at 15:30, Bruno Wolff III wrote:
On Fri, Aug 27, 2004 at 13:32:07 +0530,
Yateen Joshi <yj****@starent networks.com> wrote:
Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?


A simple way to force this is to add a primary key and a constraint
that forces the primary key to be a particular value.


Is it reasonable / possible to add a check constraint something like
select count(*) from table <=1?
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #3
On Sun, Aug 29, 2004 at 15:38:45 -0600,
Scott Marlowe <sm******@qwest .net> wrote:
On Sun, 2004-08-29 at 15:30, Bruno Wolff III wrote:
On Fri, Aug 27, 2004 at 13:32:07 +0530,
Yateen Joshi <yj****@starent networks.com> wrote:
Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?


A simple way to force this is to add a primary key and a constraint
that forces the primary key to be a particular value.


Is it reasonable / possible to add a check constraint something like
select count(*) from table <=1?


It should be possible to do that with an after trigger, but it is a bit
more work to set up. As long as the table gets vacuumed, either way
is probably reasonably fast.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #4
Yateen Joshi wrote:
Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.

So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that table.

How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?

Thanks and regards,

Yateen V. Joshi

You could try:

id INT PRIMARY KEY NOT NULL DEFAULT(1) CHECK (id = 1),

Tim

Nov 23 '05 #5

--- Scott Marlowe <sm******@qwest .net> wrote:
On Sun, 2004-08-29 at 15:30, Bruno Wolff III wrote:
On Fri, Aug 27, 2004 at 13:32:07 +0530,
Yateen Joshi <yj****@starent networks.com> wrote:
Hi,

I have got a table which is supposed to contain only one row. It does not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like it (the insert) to fail if there is already a row existing in that table.
How can I do that? Can I add any constraints? Or do I need to write a separate trigger for the same?
A simple way to force this is to add a primary key

and a constraint
that forces the primary key to be a particular

value.

Is it reasonable / possible to add a check
constraint something like
select count(*) from table <=1?


ISTM most natural to do this with a rule, e.g.:

CREATE RULE my_insert_rule AS ON INSERT TO my_table DO
INSTEAD NOTHING;

Which will cause all inserts to be silently dropped.
If you want to return a message to the application,
you could use a statement trigger, which I believe we
don't have yet, or you could use a rule like:

CREATE RULE my_insert_rule AS ON INSERT TO my_table DO
INSTEAD SELECT 'Inserts to my_table not allowed!';

Although the application may not be expecting a return
message, and might not handle it.



---------------------------(end of
broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose
an index scan if your
joining column's datatypes do not match



_______________ _______________ _
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush

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

Nov 23 '05 #6
> ISTM most natural to do this with a rule, e.g.:

CREATE RULE my_insert_rule AS ON INSERT TO my_table DO
INSTEAD NOTHING;

Which will cause all inserts to be silently dropped.


This strikes me as bad programming practice. Errors should be reported,
not silently ignored. If the application is doing an insert when it doesn't
need to, then the application is flawed as well.
--
Mike Nolan

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #7
Tim Penhey wrote on 30.08.2004 23:12:
I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.

So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that table.

You could try:

id INT PRIMARY KEY NOT NULL DEFAULT(1) CHECK (id = 1),


I like that approach :)

But should you also prevent DELETE's from that table? Otherwise you could
wind up with no rows at all. I guess that would have to be done using a rule...

Thomas
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #8
> But should you also prevent DELETE's from that table? Otherwise you could
wind up with no rows at all. I guess that would have to be done using a rule...


Why not just revoke the delete privilege?
--
Mike Nolan

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #9
Mike Nolan wrote on 31.08.2004 21:46:
But should you also prevent DELETE's from that table? Otherwise you could
wind up with no rows at all. I guess that would have to be done using a rule...

Why not just revoke the delete privilege?

That was one of my first guesses as well, but then I'm not sure if you can
revoke DELETE and INSERT privilege from the owner of the table...

Thomas
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #10

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

Similar topics

3
12028
by: Bob Sanderson | last post by:
I have a number of pages containing tables. Most have background images which have a single pixel border. The tables themselves do not have borders. For various reasons, I have to create one table without an image, so the border must be defined by the table. However, the table border does not look exactly like the single pixel one in the images. It appears to have some shading. I have tried various CSS elements but have not been able...
4
2789
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
3
2270
by: Paul Janssen | last post by:
Hello! Can anyone help me out with the following situation: (a) a single query with 550 id's in the IN-clause resulting into 800+ seconds; (b) 550 queries with a single id in the IN-clause resulting into overall time of <60 seconds; The table consists of 950.000 records, and the resultset consists of 205.000 records.
1
2616
by: Ken | last post by:
Help! I have a MS Access database made up of a single table. The data updates for this database comes in the form of a single Excel spreadsheet, which is imported into the database table. I need to break-out this single database table, into multiple tables to better structure the database and reduce the need to input the same data repeatedly.
0
2234
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability, architecture. Case 1: On a web page I would like to render a dropdown list
3
1352
by: Geoff Jones | last post by:
Hi Using code like: dataAdaptor1.Update(dataSet1.Table("MyTable")) it is possible to update a datasource with all the rows in MyTable. What is the code to update a certain row in MyTable?
3
1416
by: arteezan | last post by:
Mabuhay! I'm new in PHP and i want to create a single PHP page where the links are linked to contents within that single page. can anyone please help me with this? thanks in advance to anyone who is willing to help!
5
2987
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML document into a text document with a single row for each parent node (that has all of the values from all of the child nodes for that row) The DataView within VS 2005 IDE displays my 15 or so child tables - and knows that some parent rows...
1
1217
by: sqldba20 | last post by:
Folks: I need help with a script. I have 4 tables with AsOfDate, Country and FactorInt columns. In each table AsOfdate and Country are the same for that date but the FACTORINT column varies. I want the output in a single table (master table) and it should be in this format and look like this: TBLMASTER AsOfDate Country Factor1 Factor2 Factor3 Factor4...
0
6421
debasisdas
by: debasisdas | last post by:
The following sample code is designed to display the use of accepting a list of values in a single parameter and process the same in the where clause inside a procedure. STEP1:-First create an user defined type . CREATE OR REPLACE TYPE SPLIT_TBL AS TABLE OF VARCHAR2(32767); STEP2:-Create a function to split the list of values in a single parameter. CREATE OR REPLACE FUNCTION SPLIT (
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10250
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.