Top 3 differences between PostgreSQL and MS SQL
I recently switched a database server from Microsoft SQL Server over to PostgreSQL. Here are the top three differences in SQL:
- NO TOP, so
SELECT TOP 10 * FROM table, becomesSELECT * FROM table LIMIT 10you can also use the maxrows attribute of CFQUERY to do this, if you want cross db code (which is good). MySQL also uses the LIMIT sytax, but Oracle uses yet another syntax -
LIKE statements are case sensitive in postgresql, they can be made case insensitive like this:
SELECT * FROM table WHERE LOWER(column) LIKE '%#LCase(var)#%'(Or you can use the ILIKE operator) -
The plus operator cannot be used for concatination so
SELECT firstname + ' ' + lastname AS fullnamebecomesSELECT firstname || ' ' || lastname AS fullnamethis way works on both servers.
Tweet
Related Entries
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL - February 18, 2008
- SQL to Select a random row from a database table - September 14, 2005
- SQL Reserved Key Words Checker Tool - March 28, 2005
- Top 10 Reserved SQL Keywords - October 28, 2008
- SQL Case Statement - October 15, 2008
Trackbacks
Comments
Recently started my first project built entirely on Open Source tools etc... I've been a MS SQL programmer for years now, and am impressed with PostgreSQL's ability to equal the production level of MS SQL.
However, the learning curve for such a switch is slightly more steep than to MySQL, but this makes it clear how good PostgreSQL is for what I require.
These three differences, are the features I probably use the most when working with data directly. Thanks!
I'm all for cross platform, but to be honest, I've seen a client who, after the code was completed, just decided to change database servers. Even if they did, if your code is already properly abstracted anyway, in CFCs, this is not a big deal.
Another option to write cross db code - do what I did in BlogCFC. Simply make the current db a setting, and check for it in your queries. Yes, it's more work, but again, the benefits more than outweigh the cost of using maxrows.
I guess the reason I think maxrows is a good idea, is because the JDBC api has a setMaxRows method, which could in theory be used to limit the amount of rows returned by the server if the JDBC drivers were smart enough to do so. In practice they don't do this... bummer.
In MSSQL you could easily use this query: SELECT * FROM table_a WHERE id NOT IN ( SELECT a_id FROM table_b )
But for Postgres you should use: SELECT table_a.* FROM table_a LEFT JOIN table_b ON table_a.id = table_b.a_id WHERE table_b.a_id IS NULL
Both query have the same result but very different performance. In MS-SQL, subquery perform 3times faster than using JOIN. In PostgreSQL, the subquery will perform much-much slower than using JOIN. Try this with at least 10.000 record in both table, and you will get frustated with subquery in Postgres. Hope someone in Postgres dev fix this.
Kndly Regards Siva
Be glad that you went from SQL-Server to PostgreSQL. If you're moving from an MVCC database like Oracle or PostgreSQL to SQL Server then there are all kinds of headaches you run into because of SQL Server's locking issues, lack of decent foreign key support, etc.
The postgres DBlink module provides cross database querying.
2) You can tune both DB engines, but you can only recompile PG to match your hardware *precisely*.
3) PG is much more stable.
4) PG is much more secure, due to frequent and thorough code reviews.
5) SQL Server integrates well with Microsoft products. PG integrates well with MS products as well as 3rd party products (Oracle etc.).
6) PG has a built in GIS supportDB, if you chose to install it. SQL server has to have it hacked in.
That's just off the top my head.
SQL Server: Lots of Money
PostgreSQL: Free
I like that PostgreSQL is platform independent.
I would recommend from experience running PostgreSQL on a Linux server like RedHat or CentOS for best results.
SELECT table_a.* FROM table_a where NOT EXISTS (select ' from table_b WHERE table_a.id = table_b.a_id)
Selecting ' forces indexes to be read if they exist on table_b.a_id.
I want to make select query which having where condition between two database. In mysql it is very easy e.g. Select * from db1.table1 a,db2.table1 b where a.id=b.id
please help me.
Now we are plan to migrate our SQL Server Database to PostgreSQL. so Kindly help me to migrate what are the steps we need to follow and how to write a functions with Query Results.
Kindly help me.
Post a Comment
Recent Entries
- Writing Secure CFML cfObjective 2013 Slides
- Upgrading to Java 7 on Linux
- J2EE Sessions in CF10 Uses Secure Cookies
- Learn about ColdFusion Security at cfObjective 2013
- Session Loss and Session Fixation in ColdFusion
- FuseGuard 2.3 Released
- CKEditor Spell Checker Plugin
- Adobe Says Go Ahead and Upgrade your ColdFusion JVM


add to del.icio.us


