Showing posts with label pgAdmin 4. Show all posts
Showing posts with label pgAdmin 4. Show all posts

Thursday, September 19, 2019

Remove NOT NULL Constraint in Postgresql Using SQL Script

So I have a table called 'changes' with column name 'test' and it's constraint as 'NOT NULL'

To remove NOT NULL constraint, just execute this script in pgAdmin :


alter table changes alter column test drop not null;

Result :

Wednesday, September 18, 2019

Create a Very Simple Trigger in pgAdmin 4 - Postgresql

This post will gonna guide you to create a very simple simple trigger in pgAdmin 4.
First thing first is create a new trigger function inside a schema. Please follow the step frow below pictures

Then put the trigger function name :
Then put the code as shown below

So here we only add a RAISE NOTICE. This is actually like a logger, so everytime this function is executed there will be a notification message in our pgAdmin console. Later we'll gonna see the result. And for return NEW, we'll gonna explain it later in more detail in the next post. Well... That's alll,... Just hit the SAVE button aaand we'll gonna see our trigger functions in the list like this :

Next.....
Let's choose a table to trigger our trigger function. In this post I chose akatsuki_users. So inside of akatsuki_users just right click the Triggers menu and choose "Create --> Trigger" :
Then put a trigger name :
Choose trigger function from dropdown list :

Specify the trigger event :
The last step is hit SAVE button... and doneee.... yeeeei.....

Next... Let's try it.....
And because this trigger is fired when INSERT and UPDATE sooo let's try to insert something to akatsuki_users :
So we can see our notification message from our trigger function. But this is an INSERT. Let's try UPDATE :


Coool... So from INSERT and UPDATE we can see that our trigger function is successfully triggered...