Skip to content

PostgreSQL improvement SqlProvider #367

Description

@rafaelleonel

PostgreSQL in the inves SqlProvider to guess the name of the sequence he handle the default value of the column

  • Problem: This may generate error for those not referenced sequence at the default value of the column
  • Alternative: It would use the return already available in version ~ 8 (More would have to identify the version to change the method as version support)

New:

var name =
    attr != null ?
        "'" + attr.SequenceName + "'" :
        Convert(
            string.Format("(  SELECT "
                          + @"   CASE WHEN (pg_attrdef.adsrc ~* 'nextval') is null"
                          + @"   then null"
                          + @"   else SUBSTRING(pg_attrdef.adsrc FROM E'nextval\\(''([^'')]+)''') "
                          + @"   end as NameSequence "
                          + @" FROM pg_attribute "
                          + @" LEFT JOIN pg_attrdef ON (pg_attribute.attrelid = pg_attrdef.adrelid AND pg_attribute.attnum = pg_attrdef.adnum) "
                          + @" INNER JOIN pg_class ON (pg_attribute.attrelid = pg_class.oid) "
                          + @" WHERE lower(pg_class.relname) = lower('{0}') "
                          + @" and lower(pg_attribute.attname) = lower('{1}') "
                          + ")", into.PhysicalName, into.GetIdentityField().PhysicalName),
            ConvertType.NameToQueryField);

AppendIndent(sb)
    .Append("SELECT currval(")
    .Append(name)
    .AppendLine(")");

Old:

var name =
    attr != null ?
        attr.SequenceName :
        Convert(
            string.Format("{0}_{1}_seq", into.PhysicalName, into.GetIdentityField().PhysicalName),
            ConvertType.NameToQueryField);

AppendIndent(sb)
    .Append("SELECT currval('")
    .Append(name)
    .AppendLine("')");

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions