Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement batch runner for postgresql. #193

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

raol
Copy link

@raol raol commented Dec 9, 2015

In general it's almost copy/paste of MySqlBatchRunner class.
Slight modifications:

  • changed queries to postgresql syntax
    UPDATE
    SET
    FROM ( )
  • slighly modified regular expression with self updates.
    ColumAlias is optional group now. Alias is not generated every time.
  • When in TransactionScope it means we have open transaction, really, it is.
    Postgre treats such transaction as distributed, that's why opening new transaction fails.

In general it's almost copy/paste of MySqlBatchRunner class.
Slight modifications:
- changed queries to postgresql syntax
  UPDATE <what to update>
  SET <expression>
  FROM ( <generated select query> )
- slighly modified regular expression with self updates.
  ColumAlias is optional group now. Alias is not generated every time.
- When in TransactionScope it means we have open transaction, really, it is.
  Postgre treats such transaction as distributed, that's why opening new transaction fails.
@KivraS
Copy link

KivraS commented Feb 17, 2016

Is there any other Relevant Commit or Fork Concerning Postgre SQL?
I have downloaded this Commit Source , Needed to Change syntax from
(schema.table ) to ("schema"."table") and also ( columnName) to ("columnName") .
But otherwise it worked fine for a batch update i needed. Too bad it didn't got merged into the master branch , since a Postgresql handler is missing.

- Previously we detected outside transactions using System.Transaction, but recently
  we overcame the issue using specific configuration of the PgSql devart provider.
  It's redundant code now and should be removed to make everything consistent
  with the rest of the code.
@raol
Copy link
Author

raol commented Mar 4, 2016

@KivraS, I'm not sure I've got your point. You are saying that the generated query by PgSqlBatch runner is incorrect. Right?
It seems you're using TableNames and ColumnNames instead of tablenames, i.e. your schema is not lowercase. Right?
If so, I will make additional changes to handle such cases.

@KivraS
Copy link

KivraS commented Mar 4, 2016

"dbo" is the Schema name, "Transport" is the Table name.
For example. Previously the Runner Generated this sql.

select * from dbo.Transport where Id = 450

If you run this code on pg Admin on Postgresql 9.3 you get

ERROR: relation "dbo.transport" does not exist
LINE 1: select * from dbo.Transport where Id = 450

Correct syntax to work is

select * from dbo."Transport" where "Id" = 450

I have managed to use your PsqlBatchRunner by altering some lines.
For example

Line 122
deleteCommand.CommandText = sqlBuilder.ToString().Replace("[","").Replace("]", "");
To
deleteCommand.CommandText = sqlBuilder.ToString().Replace("[","\"").Replace("]", "\"");

And similarly for column names and Update queries.

@raol
Copy link
Author

raol commented Mar 4, 2016

@KivraS Okay. Clear. Will fix my code. Thanks.

- Table and column names that are not lowercase are caused the error. So it's necessary
  to put them in quotes.
  More info here
  http://www.postgresql.org/docs/current/interactive/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants