help-recutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Duplicate entries


From: Jose E. Marchesi
Subject: Re: Duplicate entries
Date: Wed, 25 Dec 2024 11:08:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hello Andrii.

  %rec: Person
  %unique: Age

tells recutils that, at most, one field Age will appear in each record
set.  It makes no sense for a person to have more than one Age.
Remember in a record in principle you can generally have any number of
fields having the same name.  %key implies both %mandatory and %unique,
i.e. there must be a field with the given name, and only one.

%key also introduces additional restritions.  From the manual:

   '%key' makes the referenced field the primary key of the record set.
   The primary key behaves as if both '%unique' and '%mandatory' had
   been specified for that field.  Additionally, there is further
   restriction, viz: a given value of a primary key field may appear no
   more than once within a record set.

If you want to have non-key fields with similar restrictions, you want
to use "singular fields".  From the manual:


  Sometimes we require certain fields with a given name to not appear in
  a record set featuring the same contents, but we don't want (or we
  can't) declare such fields as the key of the record set.

  In these circumstances we can use singular fields, which are declared
  as such in the record descriptor using the %singular special field:

So, in your case, you could use:

  %key: filename
  %singular: url

Now, I would expect recins to error out if you try to insert more than
one record with the same filename and/or same url.  The behavior shall
be identical to what recfix does...

> Hello, folks!
> I having trouble stopping duplicate entries from being added to my .rec
> file. Even though I've used %unique and %key settings, duplicates still
> get through.
>
> Here is my "articles.rec" file setup:
>
> ```
> %rec: Article
>
> %type: id int
> %type: url line
> %type: filename line
> %type: downloaded_on line
>
> %key: filename
> %unique: url
> ```
>
> I use this recins command to add new entries:
>
> ```
> recins -t Article \
>   -f filename -v "$FILENAME" \
>   -f url -v "$1" \
>   -f downloaded_on -v `date --rfc-3339=date` \
>   videos.rec
> ```
>
> I thought the %key and %unique settings would stop duplicate filename or
> url entries, but duplicates still get added.
>
> Current workaround:
> ```
> if ! recsel -e "filename = '$FILENAME'" articles.rec | grep -q .; then
>     recins -t Article \
>       -f filename -v "$FILENAME" \
>       -f url -v "$1" \
>       -f downloaded_on -v `date --rfc-3339=date` \
>       articles.rec
>
> else
>     echo "Record with filename '$FILENAME' already exists."
> fi
> ```
>
> Is there a way to make recins automatically reject duplicates? Or do I
> need to check for duplicates myself before running the command?
>
> Thanks in advance!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]