Sunday, April 15. 2012ODBC Foreign Data wrapper to query SQL Server on Window - Part 2Printer FriendlyTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Thank you for this work and the good explanations.
However, I tried to apply the recommended steps, but the only result is an empty one (columns are displayed with no data lines, as if the foreign table contained no record). I’ve built a test table on SQLServer 2005, named “testPG”, containing 2 columns (iId Integer NOT NULL, cName Varchar(20) NOT NULL), and inserted 2 rows (1, “One”) and (2, “Two”). I created a system dsn named SystemSQLServerPourPG which I tested successfully using MSVisualFoxPro and MSAccess. Then I created the PostGreSQL script as follows : CREATE EXTENSION odbc_fdw ; CREATE SCHEMA super_store_SQLServer ; CREATE SERVER TestSQLServer FOREIGN DATA WRAPPER odbc_fdw OPTIONS (dsn 'SystemSQLServerPourPG'); CREATE USER MAPPING FOR postgres SERVER TestSQLServer OPTIONS (username 'sa',password 'mdp'); CREATE FOREIGN TABLE super_store_SQLServer.TestSQLServer (iId Integer NOT NULL , cNom Varchar(20) NOT NULL) SERVER TestSQLServer OPTIONS (database 'superstore_SQLServer' , schema 'dbo' , sql_query 'iId, cNom FROM dbo.testPG;' , sql_count 'select count(iId) from dbo.testPG;'); SELECT * FROM super_store_SQLServer.TestSQLServer ; The result is an empty result as said earlier. Did I write something wrong ? NB : more tests showed that : * the same result is obtained when using a dsn which does not exist (without any error message) * the same result is obtained when using an invalid login or password (without any error message) * the same result is obtained when using an invalid SQL Query (either syntaxically correct or not) (without any error message) * using wrong parameters names in the CREATE FOREIGN TABLE options causes a crash of the server (without any error message, but you have to restart service), when using an invalid option (e.g “dsnerror” instead of “dsn”) in the CREATE SERVER query brings the following message : “option « dsnerror » invalide”. Hope you can help. Luc
Luc,
the ODBC FDW doesn't like different casings. I had similar issues if I had my select with mixed casing column names. Doesn't matter how it is in sql server, but when you write the select fields should be all lowercase. So try changing your foreign table to this: CREATE FOREIGN TABLE super_store_SQLServer.TestSQLServer (iid Integer NOT NULL , cnom Varchar(20) NOT NULL) SERVER TestSQLServer OPTIONS (database 'superstore_SQLServer' , schema 'dbo' , sql_query 'iid, cnom FROM dbo.testPG;' , sql_count 'select count(iId) from dbo.testPG;');
Thank you for your answer, but this did not solve the problem.
Notice : in the "Messages" tab, PG wrote the fllowing after executing te select on my foreign table : ------------------------- NOTICE: Opps! Durée totale d'exécution de la requête :32 ms. 0 ligne récupérée. -------------------------
I had similar issue with one large table. I didn't revisit to see what the issue is.
Can you do a query with the information_schema.tables without it crashing. The example I have above for information_schema.tables should work for any sql server since sql server has that schema and table as well.
Luc,
I noticed your SQL statement is missing the SELECT word. Also Forgot to mention. I had a similar issue with another table recently. I had forgotten to put in the sql count query. I thought that was optional, but turns out you get a crash in some cases if you leave it out. Keep in mind the driver is alpha quality. though it looks like you have that in, but you might want to verify your SQL and count queries work fine when run in sql server.
Hi,
Would it be possible to post the ODBC FDW binaries for windows 64bit PostgreSQL 9.2? I've tried to compile myself with MinGW but after two long nights this seems to be way out of my league:) Rytis
Unfortunately I don't think so. Or at least not last time I tried. I tried a couple of months ago and it wouldn't compile against. 9.2 changed FDW in a major way whcih broke a lot of past FDWs. I was trying to see if I could patch the code up to work with 9.2 but got as far as getting it to compile, but then it failed on load. Then I had to move on to something else. I'll check if its been updated recently.
|
Entry's LinksQuicksearchCalendar
Categories
Blog Administration |