Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation in postgreSQL [closed]

Tags:

postgresql

I made an application to collect data from users. Those data will be collected at different places and from these places will be sent to a central server. I need to design a validation plan for the central server in PostgreSQL. Data must be checked against various validations and if a validation fails a message must be thrown.

It is database to database transfer validation.

like image 867
user1686308 Avatar asked Sep 20 '12 14:09

user1686308


People also ask

How do I close PostgreSQL?

Type \q and then press ENTER to quit psql . As of PostgreSQL 11, the keywords " quit " and " exit " in the PostgreSQL command-line interface have been included to help make it easier to leave the command-line tool.

How do I drop a primary key in PostgreSQL?

The syntax to drop a primary key in PostgreSQL is: ALTER TABLE table_name DROP CONSTRAINT constraint_name; table_name. The name of the table to modify.

How do I view constraints in PostgreSQL?

To find the name of a constraint in PostgreSQL, use the view pg_constraint in the pg_catalog schema. Join the view pg_catalog. pg_constraint with the view pg_class ( JOIN pg_class t ON t. oid = c.

How do you change constraints in PostgreSQL?

The syntax for creating a unique constraint using an ALTER TABLE statement in PostgreSQL is: ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column1, column2, ... column_n); table_name.


1 Answers

Yes you're on the right track, you'll either use triggers and/or check constraints to do this.

Also, PostgresQL has a very flexible type system. Make sure to select the most appropriate, restrictive types. You can even define custom types yourself.

  • UNIQUE constraints
  • CHECK Constraints
  • FOREIGN KEY constraints - tutorial
  • Triggers, which can call helper functions written in any supported procedural language. Triggers can RAISE EXCEPTION to abort a transaction.
  • Domain Types
  • EXCLUSION constraints in 9.2 and newer
  • Multi-column PRIMARY KEYs
  • Partial UNIQUE indexes

Note that instead of using varchar(length) you're usually better off using text and a check constraint.

like image 72
C. Ramseyer Avatar answered Sep 22 '22 05:09

C. Ramseyer