Skip to content

Table name and attribute case are supported #38

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Serilog.Sinks.PostgreSQL/Sinks/PostgreSQL/PostgreSQLSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class PostgreSQLSink : PeriodicBatchingSink
private readonly IFormatProvider _formatProvider;
private readonly bool _useCopy;

private const string split ="\"";
public const int DefaultBatchSizeLimit = 30;
public const int DefaultQueueLimit = Int32.MaxValue;

Expand Down Expand Up @@ -116,10 +117,10 @@ private string GetFullTableName(string tableName, string schemaName)
var schemaPrefix = String.Empty;
if (!String.IsNullOrEmpty(schemaName))
{
schemaPrefix = schemaName + ".";
schemaPrefix = split + schemaName+ split+".";
}

return schemaPrefix + tableName;
return schemaPrefix + split + tableName + split;
}


Expand Down Expand Up @@ -184,15 +185,15 @@ private void ProcessEventsByCopyCommand(IEnumerable<LogEvent> events, NpgsqlConn

private string GetCopyCommand()
{
var columns = String.Join(", ", _columnOptions.Keys);
var columns = split+String.Join($"{split},{split}", _columnOptions.Keys)+ split;

return $"COPY {_fullTableName}({columns}) FROM STDIN BINARY;";

}

private string GetInsertQuery()
{
var columns = String.Join(", ", _columnOptions.Keys);
var columns = $"{split}{String.Join($"{split}, {split}", _columnOptions.Keys)}{split}";

var parameters = String.Join(", ", _columnOptions.Keys.Select(cn => ":" + ClearColumnNameForParameterName(cn)));

Expand Down
3 changes: 2 additions & 1 deletion Serilog.Sinks.PostgreSQL/Sinks/PostgreSQL/TableCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public static void CreateTable(NpgsqlConnection connection, string tableName, ID

private static string GetCreateTableQuery(string tableName, IDictionary<string, ColumnWriterBase> columnsInfo)
{
var split = "\"";
var builder = new StringBuilder("CREATE TABLE IF NOT EXISTS ");
builder.Append(tableName);
builder.AppendLine(" (");

builder.AppendLine(String.Join(",\n", columnsInfo.Select(r => $" {r.Key} {GetSqlTypeStr(r.Value.DbType, r.Value.ColumnLength)} ")));
builder.AppendLine(String.Join(",\n", columnsInfo.Select(r => $" {split}{r.Key}{split} {GetSqlTypeStr(r.Value.DbType, r.Value.ColumnLength)} ")));

builder.AppendLine(")");

Expand Down