0

In PostgreSQL, how can I restrict count of rows, I mean I have table which is users and I want to set a limit for example 10 so 10 must be the top limit of count. How can I do that ?

Thanks in Advance...

9
  • You need to use a trigger Commented Feb 4, 2015 at 16:06
  • could you spesify it ? what do you mean by trigger ? Commented Feb 4, 2015 at 16:08
  • what do you mean by limit count? do you mean limit the number of rows returned? or you are counting rows and you want the max count to be 10? Commented Feb 4, 2015 at 16:24
  • I want to have maximum 10 users, I think it's more clear now. Commented Feb 4, 2015 at 16:26
  • have you made any attempts? any sql code you have? maybe something like this? SELECT * FROM users LIMIT 10; Commented Feb 4, 2015 at 16:28

1 Answer 1

3

You can use a CHECK constraint on an id number.

create table users (
  user_id integer primary key
    check (user_id between 1 and 10),
  user_name varchar(35) not null
);

I think you're better off with an integer than with serial for this, since you're using only 10 rows.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.