Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
PostgreSQL - Some Basics
WhatsApp
Dinesh Gabhane
4y
9.8
k
0
6
25
Blog
Recently, I worked on one migration project and migrated an Oracle database to PostgreSQL. I came across some really important observations while writing the scripts and executing in PostgreSQL. Below are some observations.
When we create a TABLE, we need to mention the SCHEMA name as below.
SCHEMANAME."TABLENAME" if you use only Table name it will get created in PUBLIC Schema.
While creating a TABLE, prefer the table name in a double quote (like “TABLENAME”); else, it will get considered as small letters (like tablename). Even if you use Pascal case (TableName), it will treat that as lowercase (tablename).
If SYSDATE or GETDATE() is not available, you can use NOW().
There are many data types available -
NUMBER is NUMERIC
VARCHAR2 is VARCHAR
BLOB is BYTEA
LONG is CHAR, VARCHAR, TEXT
and many more
You can refer to this link for the conversion of data types from ORACLE to PostgreSQL (
https://www.cybertec-postgresql.com/en/mapping-oracle-datatypes-to-postgresql/
)
While fetching the data from a table, we can use Schema name with Table name like below.
SCHEMANAME."TABLENAME"
You cannot create a TRIGGER directly on the TABLE. So, you first need to create a Trigger Function and call it as Trigger.
For example -
CREATE
OR
REPLACE
FUNCTION
SCHEMANAME.TEST_TRIGGER()
RETURNS
trigger
AS
$$
BEGIN
select
TEST_ID.nextval = new.TEST_ID
from
dual;
END
;
$$
LANGUAGE
'plpgsql'
;
CREATE
TRIGGER
SCHEMANAME.TEST_TRIGGER
BEFORE
INSERT
ON
SCHEMANAME.
"TESTTABLE"
FOR
EACH ROW
EXECUTE
PROCEDURE
SCHEMANAME.TEST_TRIGGER();
When you call a
FUNCTION
and store the result in a variable, you can use this query.
SELECT
GETPHONENO(param1 , param2)
AS
PHONENO;
You can declare a CURSOR, use this query.
DECLARE
C1
CURSOR
FOR
SELECT
*
FROM
ERR_LOG_FLAG
That's it for now. I will come up with more details of PostgreSQL in my upcoming posts.
Databases DBA
PostgreSQL
Up Next
Day 1 - Setup PostgreSQL with SQLectron
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Blue Ocktopus Technology Systems Private Limited
Enabling revenue generation through brand loyalty and customer retention for enterprise retail and e
Membership not found